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
Post a Comment