I'd love some help with a simple jQuery script that searches for a specific string of text. If that text exists, then manipulate the containing div's css. The HTML would look like:
<div class="container">
<div>
<div class="heading">
<a href="#">Very important text</a>
</div>
</div>
</div>
<div class="container">
<div>
<div class="heading">
<a href="#">Not important at all</a>
</div>
</div>
</div>
<div class="container">
<div>
<div class="heading">
<a href="#">Very important text</a>
</div>
</div>
</div>
<div class="container">
<div>
<div class="heading">
<a href="#">Not important at all</a>
</div>
</div>
</div>
For example: If a container contains the string "Very important text" I would like to give the 'heading' class a height of 200px and its 'container' div a background of green. Please let me know if this is unclear. Thanks in advance!
CHeers.
use :contains selector in Jquery .
or simply
Fiddle
You can do this:
Demo:http://jsfiddle.net/AmitJoki/y82X9/1
As Zword suggested, use filter. This solution is the fastest. JSPerf
Using filter is a faster and better option:
Demo Fiddle
See test : http://jsperf.com/so-22877172
just use this ..
$(".container div:contains('Very important text')").parent().css("height","300");
you can play around .