2.2.4 元素选择器
元素选择器允许通过元素的名称来查找它们
可假设想查找页面中的所有<div>元素,为了实现这个目标,必须编写如下代码:
<div>
<h1 class="green">A title</h1>
<p class="fff">I'm a paragraph</p>
<p class="fff">888888888</p>
</div>
<div>
<h1 class="green">Another title</h1>
<p class="gggg">I'm yet another paragraph</p>
</div>
<script src="jquery-1.6.4.js" type="text/javascript"></script>
<script>
console.log($('div')[0].innerHTML);
</script>
选择页面中的<div>和<span>元素
<div><span>测试11</span></div>
<div>
<h1 class="green">A title</h1>
<p class="fff">I'm a paragraph</p>
<p class="fff">888888888</p>
</div>
<div>
<h1 class="green">Another title</h1>
<p class="gggg">I'm yet another paragraph</p>
</div>
<div><span>测试</span></div>
<script src="jquery-1.6.4.js" type="text/javascript"></script>
<script>
console.log($('div,span')[0].innerHTML);
</script>