javascript - Adjacent elements have spaces, how to find out the previous sibling element it is adjacent to, instead of #text?
ringa_lee
ringa_lee 2017-06-30 09:52:23
0
1
729
<u>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</u>
aA=document.getElementsByTagName('li');

Take out the li element
Then bind the click event

for(var i = 0; i < aA.length; i++) {
    aA[i].onclick = function () {

Now I click on the second li element, but I want to find out the adjacent sibling elements of the second li element

Then I used .previousSibling; but what I found was #text, not the first li element.
When I deleted all the spaces in ul, what I found was the first element. element

Then now I want to find the previous sibling element of the li element without deleting spaces. Without using JQ

How to implement this function

ringa_lee
ringa_lee

ringa_lee

reply all(1)
滿天的星座

previousElementSibling Go check it out

另一种就是获取自己是第几个,然后parentElement然后children然后自己个数加减
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template