<ul>
  <li>John</li>
  <li>Karl</li>
  <li>Brandon</li>
</ul>

获取第一个元素:  $("ul li:first-child")

<div > 

  <ul>
    <li>John</li>
    <li>Karl</li>
    <li>Brandon</li>
  </ul>

</div>

获取第一个元素:  $("#getfirst").find("ul li:first-child")

或$("#getfirst").find("ul li").get(0)

或$("#getfirst").find("ul li").first()

 

 

 

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

JQ获取上一个元素:$("#getfirst").prev()

JQ获取下一个元素:$("#getfirst").next()

JS获取上一个元素:document.getElementById("compcode240").previousSibling

JS获取下一个元素:document.getElementById("compcode240").next

JQ获取第一个子元素:$("#getfirst").find("ul li:first-child")

JS获取第一个子元素:document.getElementById("compcode240").firstChild

 

相关文章:

  • 2021-12-26
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-12-12
  • 2021-12-14
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2021-07-30
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案