javascript - Iterate through HTML div and extract the value from a child span using JavaScript or jQuery
问题描述
How do I find a value in a nested div in JavaScript and hide the div
as an example, if my input to the JavaScript function is Florida.
I would like to loop thru the divs (class name = state-name) , get the value of the inner span (class ="state"). If the value match my input value (Florida) then hide that parent div (state-names) .
<div class="state-names panel panel-default" ">
<div class="panel-heading">
<h3 class="panel-title">
<a> <span class ="state">Alabama (6)</span></a>
</h3>
</div>
</div>
<div class=" state-name panel panel-default" ">
<div class="panel-heading">
<h3 class="panel-title">
<a> <span class ="state">Florida (2)</span></a>
</h3>
</div>
</div>
<div class=" state-name panel panel-default" ">
<div class="panel-heading">
<h3 class="panel-title">
<a> <span class ="state">Texas (16)</span></a>
</h3>
</div>
</div>
How can iterate thru the html tags and get the span value in JS or Jquery
Thanks
解决方案
You can do this using jQuery as below:
$('.state-names').each(function(i, obj) {
if($(this).text().includes("Florida")){
console.log("Found Florida")
$(this).hide()
}
});
推荐阅读
- swift - 如何将 pdf 文件从 Firebase 保存到文档目录
- javascript - 无论如何要使用猫鼬填充不同的值
- java - 同步访问问题
- javascript - 预期换行符为“LF”,但发现“CRLF”但仅在一个文件中
- sql - 当您有列名“日期”时如何订购表 desc?
- python - 在 Python 中删除前一行后打印一行
- javascript - 当validationMessageFor 助手在屏幕上收到任何消息时,不应执行onclick
- python - 在流中使用 python sql 函数时无法检索字段 [{0}] TabPy 错误的结果
- html - 保持动态内容的容器高度
- python-3.x - 如何在 Conv 神经网络 (Unet) 中输入 nifti 图像