Blogger Information
Blog 42
fans 5
comment 0
visits 38189
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jq 选择器,#id .class element 和 parent>p prev+next prev~siblings
张浩刚
Original
815 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  9. </head>
  10. <body>
  11. <div class="one" id='red'>div1 div1</div>
  12. <div class="two" id='blue'>div2 div2</div>
  13. <p id='f'>fff</p>
  14. <div class="three" id='gray'>
  15. <p id='a'>aaa</p>
  16. <p id='b'>bbb</p>
  17. <p id='c'><span>ccc</span></p>
  18. <p id='d'>ddd</p>
  19. </div>
  20. <p id='e'>eee</p>
  21. <p id='h'>hhh</p>
  22. <p id='i'>iii</p>
  23. <script>
  24. console.log( $('#red') ); // 通过 #id 调出div1
  25. console.log($('.two')); //通过 .class调出div2
  26. console.log($('p')); // element 调出全局p 5个
  27. console.log($('div')); // element 调出全局div 共3个
  28. ////////////////////////////////
  29. console.log($('div p')); //全局div下所有p,包含子级和孙子级
  30. console.log($('#gray p')); //调用id为gray下的所有p,包含子级和孙子级
  31. console.log($('.three p')); //调用class为three下的所有p,包含子级和孙子级
  32. ////////////////////////////////
  33. console.log($('div>p')); //全局div下所有子级p
  34. console.log($('#gray>p')); //调用id为gray下的子级p
  35. console.log($('.three>p')); //调用class为three下的子级p
  36. ////////////////////////////////
  37. console.log($('div + p')); //全局div后面的平级p
  38. console.log($('.three + p')); //class为three的后面的相邻平级p;
  39. console.log($('#gray ~ p')); // #gray的后后面的所有平级p
  40. </script>
  41. </body>
  42. </html>
Correction status:Uncorrected

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!