Reputation: 6362
How can i iterate the following DOM and to find if some li
has the value of Value2 is here
i would like to have some boolean function such as
var v = IsValueExist('Value2 is here')
<div class="span6">
<ol id="sortable1" class="rectangle-list">
<li><a href="#">Value1</a></li>
<li><a href="#">Value2 is here</a></li>
<li><a href="#">Value3 is here</a></li>
</ol>
</div>
Upvotes: 0
Views: 58
Reputation: 12815
Take a look at contains selector: http://api.jquery.com/contains-selector/
But it will return both <a href="#">Value2 is here</a>
and <a href="#">Value2 is here again</a>
As an alternative, you may do next:
var lis = $("#sortable1 li").filter(function(index){ $(this).text() == "some text"});
if(lis.length > 0) {
//sortable1 contains an element with "some text" inside
}
Upvotes: 0
Reputation: 100205
you mean something like:
if ($('#sortable1 > li:contains("Value2 is here")').length > 0) {
//found
}
Upvotes: 1