问题
I have an ajax form and I need to locate the 5 digit zip entered. -- val();
var zip = ($("#edit-field-zip-value").val());
After submit, results are loaded in a table with upto 10 zips. Within the 10 zips, one needs to be identified with jquery.
$(".zip div:html[text=zip]").addClass("equal");
The above line is obviously incorrect. Can someone help out with here. If it isn't possible with my line of jquery, I am open to another more flexible solution.
ex:
if (zip == tablezip) {
console.log("hello");
}
MARKUP:
<td>
<div class="zip">
<div>90042</div>
<div>90052</div>
<div>90062</div>
<div>90072</div>
<div>90082</div>
</div>
</td>
回答1:
The correct jQuery would be, using contains:
$('.zip div:contains('+zip+')').addClass('equal');
If you needed it to be exact, you could do:
$('.zip div').filter(function() {
return $(this).text() == zip;
}).addClass('equal');
回答2:
Are you looking for the div that contains the zip? Try the :contains selector.
$(".zip div:contains("+zip+")").addClass("equal");
来源:https://stackoverflow.com/questions/9541905/jquery-find-html-equal-to-val