html - adding a class to an anchor based on specific text in that anchor jquery -


new jquery , appreciate help.

my markup looks this:

<dl>     <dt>colors</dt>     <dd><a>red</a></dd>     <dd><a>green</a></dd>     <dd><a>blue</a></dd> </dl> 

let's wanted add specific class anchor text "green". how go that?

thanks

the :contains selector return partial matches green match green, lightgreen or darkgreen, of times choice use .filter()

$('dl a').filter(function(){     return $.trim($(this).text()) == 'green' }).addclass('newclass') 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -