Portability of nextElementSibling/nextSibling

后端 未结 3 1493
长发绾君心
长发绾君心 2020-12-03 10:44

I\'m currently writing an accordion and running into the same problem as described in nextSibling difference between IE and FF? - specifically differences between Microsoft\

3条回答
  •  攒了一身酷
    2020-12-03 11:02

    Firefox nextSibling returns whitespace \n while Internet Explorer does not.

    Before nextElementSibling was introduced, we had to do something like this:

    var element2 = document.getElementById("xxx").nextSibling;
    while (element2.nodeType !=1)
    {
              element2 = element2.nextSibling;
    } 
    

提交回复
热议问题