I want to keep a list of all divs with same class name i.e mod. For this I have sorted the list based on ascending ids. Hence I am looking for those ids whos internal div contains class title with text “Hello1” .
Here is the Structure
<div class="mod" id="mod23" >
<div class="content" >
<div class="hd" >
<div class="title">Hello1</div>
<ul class="list"></ul>
<ul class="buttons">
<li class="help"></li>
<li class="show" ></li>
<li class="close"></li>
</ul>
</div>
</div>
</div>
<div class="mod" id="mod27" >
<div class="content" >
<div class="hd" >
<div class="title">Hello2</div>
<ul class="list"></ul>
<ul class="buttons">
<li class="help"></li>
<li class="show" ></li>
<li class="close"></li>
</ul>
</div>
</div>
</div>
<div class="mod" id="mod25" >
<div class="content" >
<div class="hd" >
<div class="title">Hello1</div>
<ul class="list"></ul>
<ul class="buttons">
<li class="help"></li>
<li class="show" ></li>
<li class="close"></li>
</ul>
</div>
</div>
</div>
<div class="mod" id="mod29" >
<div class="content" >
<div class="hd" >
<div class="title">Hello2</div>
<ul class="list"></ul>
<ul class="buttons">
<li class="help"></li>
<li class="show" ></li>
<li class="close"></li>
</ul>
</div>
</div>
</div>
Here is the code I have tried to come up with which is not working
myarray is a sorted list of unique id number.
for(var i=0;i<len;i++)
{
$('#mod'+myarray[i]).each(function(index) {
$('div.title:contains(Hello1)').each(function(index) {
alert('found at ' +i);
});
});
}
Instead of
forloop and:You can use
starts withselector like this:But I assume this is what you are looking for: