一、获取当前标签

JS:

this,如下:

<button onclick="fun(this)"></button>

Jquery,如下:

$("#button").click(function(){

  $(this)

})

二、获取父标签

<div><span ></span></div>

JS:

parentNode,如下:

document.getElementById("test").parentNode

Jquery:

parent(),如下:

$("#test").parent()

三、获取子标签

<div ><span></span></div>

JS:

childNodes,如下

document.getElementById("test").childNodes

Jquery:

children(), 如下

$("#test").parent()

四、获取上一个标签

<div></div><div ></div>

JS:

previouselementsibling,如下

document.getElementById("test").previouselementsibling

Jquery:

prev(),如下

$("#test").prev()

五、获取下一个标签

<div ></div><div></div>

JS:

document.getElementById("test").nextSibling

Jquery:

$("#test").next()

  

 

相关文章:

  • 2021-05-27
  • 2022-03-07
  • 2022-12-23
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
猜你喜欢
  • 2021-10-20
  • 2021-12-20
  • 2021-12-20
  • 2021-11-17
  • 2021-04-02
  • 2022-01-13
相关资源
相似解决方案