<div>
<div id ="container">
<div>
<img src="some src>
</div>
<p>get this text</p>
<h>hello</h>
</div>
</div>
我想要主 div 中的图像总数,并且想要提取图像标签以外的 html 标签。
输出:
否。图片数量 =1
strings= <p>get this text</p><h>hello</h>
请给我一个演示
最佳答案
$("#container img").length
- 对于 img
标签数
为每个提取字符串,
$("#container").find("p, h").not("div").each(function() {
console.log($(this).get(0)); //Object
});
注意:您正在使用一些奇怪的 元素是一个无效的 HTML 标签,我认为它是 <h>
<h1>
或其他一些标题元素。
关于javascript - 在 div 中选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24968328/