css - jquery add a class to $('<a/>').click(function(){...}) -


how can add class tags such a & span in these examples:

$('<a/>').click(function(){...}) $("<span/>").text(chars.substr(0, limit-1)); 

=================

here full script. adds spans , tags portions of text. need have classes added spans or tags can style selections. has jquery 1.3x:

var limit = 200, chars = $("#showhidediv").text();  if (chars.length > limit) {     var visiblepart = $("<span/>").text(chars.substr(0, limit-1));     var hiddenpart = $("<span/>").text(chars.substr(limit-1)).hide();     var readmore = $('<a/>').click(function() {              hiddenpart.toggle();              readmore.toggle();              readless.toggle();              return false;          }).text ("show more")     var readless = $('<a/>').click(function() {              hiddenpart.toggle();              readmore.toggle();              readless.toggle();              return false;         }).text("show less").hide();     $("#showhidediv").empty()         .append(visiblepart)         .append(readmore)         .append(hiddenpart)         .append(readless);  } 

$('<a class="myclass" />').click(function() { /* ... */ }); 

or chain jquery actions:

$('<a />').click(function() { /* ... */ }).addclass('myclass'); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -