Is it possible for Jquery to add a class to a link that says read more automatically?
I want to use this within a CMS and for it to automatically turn any read more link into a button by adding a class.
Is it possible for Jquery to add a class to a link that says read more automatically?
I want to use this within a CMS and for it to automatically turn any read more link into a button by adding a class.
Yep:
$('a:contains("read more")').addClass('newlyAddedClass');
This will add the class 'newlyAddedClass' to every element that contains the string 'read more', it is case-sensitive, and relies on the :contains()
pseudo-selector.
try some class or id
..a href="---" class="myreadmore" id="myreadmore">read more ../a>
with class
$('.myreadmore').addClass("myclass");
with id
$('#myreadmore').addClass("myclass");
or use
contains("Read More »")
check previous anwere
refer http://api.jquery.com/contains-selector/ for contains selector
The following code will add a case insensitive Contains
(Note the uppercase C) selector to jQuery
jQuery.expr[':'].Contains = function(a,i,m){
return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
};
You can then use a slightly modified version of David Thomas' code:
$('a:Contains("read more")').addClass('newlyAddedClass');
Which will case insensitively match everything with "read more" (So also "Read More", "rEAd More" etc.)
Found the selector in the following question: Is there a case insensitive jQuery :contains selector?