访问javascript中的html节点
我有以下html代码访问javascript中的html节点,javascript,html,tags,Javascript,Html,Tags,我有以下html代码 <div id="polaroid"> <figure> <img src="assets/polaroid01.jpg" width="200" height="200" alt="Red mushroom" /> <figcaption>Pretty red mushroom</figcaption> </figure> <figure&
<div id="polaroid">
<figure>
<img src="assets/polaroid01.jpg" width="200" height="200" alt="Red mushroom" />
<figcaption>Pretty red mushroom</figcaption>
</figure>
<figure>
<img src="assets/polaroid02.jpg" width="200" height="200" alt="Rainbow near Keswick" />
<figcaption>Rainbow near Keswick</figcaption>
</figure>
<figure>
<img src="assets/polaroid03.jpg" width="200" height="200" alt="An old tree" />
<figcaption>Nice old tree</figcaption>
</figure>
</div><!--end polaroid-->
但我不知道如何访问图像标签。
我试过这个
document.getElementById('gall').getElementsByTagName('figure').getElementsByTagName('img');
但这不起作用 在这种情况下,使用更方便: 你的意思是这样的:
var images= document.getElementById('gall').getElementsByTagName('figure');
images.getElementsByTagName("img");
如果使用JQuery,这是可能的。就这么做吧
$(文档).ready(函数(){
$(“#宝丽来img”).css(“边框”,“1px实心”#000000”);
});
它不起作用,因为getElementsByTagName
返回一个节点列表,而不是单个节点。hmm。当您尝试上述Sheldon时,控制台中出现了哪些错误?
var images = document.querySelectorAll('#gall figure img');
var images= document.getElementById('gall').getElementsByTagName('figure');
images.getElementsByTagName("img");