How can add a class to an a href tag with specific words?
I want every instance of an a tag with ‘click here’ and ‘more information’ to add a class.
<a href="">click here</a> <a href="">more information</a>
To become:
<a href="" class="arrow">click here</a> <a href="" class="arrow">more information</a>
Some links have word-breaks on them, causing the “contains” array to miss them:
<a title="Vision and Values" href="/about-us/vision-and-values.aspx">click
here</a>
It’s not a <br/> but the HTML is rendering the two words on separate lines
Use filter, if you want to exactly match “click here”:
Or if you have a lot of conditions, use
inArrayhttp://api.jquery.com/jQuery.inArray/:That way, if you have an additional text to match, you just need to add to that array.
You could also use
contains, but it will match things likeclick here 2etc, basically anything thatcontains“click here”, but not exactly that.