jquery find .html() equal to val();

℡╲_俬逩灬. 提交于 2019-12-12 17:10:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!