Reputation: 1026
I have the following html structure, how do I search using JQuery if the dom elements in "subscribedList" has value 97 for instance?
<div id="subscribedList">
<div style="display:block;height: 30px;">
<span class="subscribeNodeNo">98</span>
<button class="unSubscribeNode btn btn-danger pull-right btn-xs">Unsubscribe</button>
</div>
<div style="display:block;height: 30px;">
<span class="subscribeNodeNo">97</span>
<button class="unSubscribeNode btn btn-danger pull-right btn-xs">Unsubscribe</button>
</div>
<div style="display:block;height: 30px;">
<span class="subscribeNodeNo">96</span>
<button class="unSubscribeNode btn btn-danger pull-right btn-xs">Unsubscribe</button>
</div>
...
...
</div>
Upvotes: 0
Views: 60
Reputation: 141
You can use jQuery(":contains(text)" ) and manipulate as needed.
$(document).ready(function () {
$("span:contains('98')" ).css("color", "#FF0000");
});
See here: http://jsfiddle.net/#&togetherjs=MMqUNg6R3l
.contains() docs on Jquery.com
Upvotes: 0
Reputation: 25527
You can check like this,
$("#subscribedList").each(function() {
if ($(this).find(".subscribeNodeNo").text().trim() == "97") {
alert("yes");
}
});
You can use filter too,
var newList = $("#subscribedList .subscribeNodeNo").filter(function() {
return $(this).text().trim() == "97"
});
Or use :contains
selector
if($("#subscribedList .subscribeNodeNo:contains('97')").length)
{
}
Upvotes: 5
Reputation: 60
Try this
$('.subscribeNodeNo').each(function(i, v){
if($(this).text() == '97'){
alert('exist');
return false;
}
})
Upvotes: 1