Blogger Information
Blog 40
fans 3
comment 0
visits 48218
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery元素选择标签练习 - 20191220
MArtian
Original
827 people have browsed it
  1. <div id="a1">我是ID</div>
  2. <div class="a2">我是class</div>
  3. <div class="a2">我是class</div>
  4. <div>我是div标签</div>
  5. <div>我是div标签</div>
  6. <div>我是div标签</div>
  7. <section>
  8. <p>我1级是P标签</p>
  9. <p>我1级是P标签</p>
  10. <p>我1级是P标签</p>
  11. <div><p>我2级是P标签</p></div>
  12. <div><p>我2级是P标签</p></div>
  13. <div><p>我2级是P标签</p></div>
  14. </section>
  15. <section></section>
  16. <p>我是P标签</p>
  1. var idElement = $('#a1'), // 获取id为a1的元素
  2. classElement = $('.a2'), // 获取所有class为a2的元素
  3. divElement = $('div'), // 获取所有div元素
  4. pElement = $('section p'), // 获取section内的所有p后代元素
  5. pElement2 = $('section > p'), // 获取section内的所有p标签子元素;
  6. div_pElement = $('#a1 ~ section'), // 获取#a1起始位置向后的所有section同级元素,不包含其他元素
  7. nextElement = $('div + section'); // 获取div后的第一个section同级元素
  8. console.log(idElement);
  9. console.log(classElement);
  10. console.log(divElement);
  11. console.log(pElement);
  12. console.log(pElement2);
  13. console.log(div_pElement);
  14. console.log(nextElement);

总结

  1. div + p div ~ section 都是同级选择器,不会返回子元素,也不包含起始元素
  2. div > pdiv p 两者的区别是,前者是子元素选择,后者是后代选择
Correcting teacher:西门大官人西门大官人

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post