Find Next Sibling Element In DOM With JavaScript

theChampion

How can I find the next element in the current scope? For example, I want to find div element and after this the next one which is p?

If I use document.getElementsByTagName('DIV')[0].nextSibling it returns #text. I want it to return p tag.

<div>
    <table>
        <tr>
            <td></td>
        </tr>
    </table>
</div>
<p></p>
Felix Kling

You can use nextElementSibling. If you need to support older browsers, traverse nextSibling until you find an Element node.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find next similar sibling moving down in the dom tree

From Dev

Javascript dom selection of next element

From Dev

Find the next element that comes later in DOM

From Dev

DOM manipulation with JavaScript or jQuery by moving element inside of its sibling

From Java

Find javascript that is changing DOM element

From Dev

Add class on sibling next to element

From Dev

Add class on sibling next to element

From Dev

XPath for next/sibling/following HTML element?

From Dev

Protractor - select next sibling of the current element

From Dev

Access next sibling <li> element with BeautifulSoup

From Dev

XPath for next/sibling/following HTML element?

From Dev

Style from next sibling element not work

From Dev

find an element inside an sibling of another element with jquery

From Dev

another jquery find next class not sibling for slideToggle

From Dev

Find next cell contained in sibling row with querySelector

From Dev

jquery .next can't find sibling

From Dev

using jquery next to find "nested" sibling

From Dev

Find next img element using known element id javascript/jquery

From Dev

Selecting Next HTML Sibling in Native Javascript

From Dev

Find preceding-sibling of the parent element in xslt

From Dev

how to get the next image tag after specific dom tag, sibling or not?

From Dev

Find next element in jquery

From Dev

Unable to find next element

From Dev

Get ID of next DOM element

From Dev

How to find and replace a string in HTML DOM element using javascript

From Dev

Javascript Quiz - problems reaching the next sibling through next() method on jQuery

From Dev

Select the next DOM element after the current element

From Dev

Inserting an element right after the sibling in Javascript

From Dev

Getting next sibling element using XPath and Selenium for Java

Related Related

  1. 1

    How to find next similar sibling moving down in the dom tree

  2. 2

    Javascript dom selection of next element

  3. 3

    Find the next element that comes later in DOM

  4. 4

    DOM manipulation with JavaScript or jQuery by moving element inside of its sibling

  5. 5

    Find javascript that is changing DOM element

  6. 6

    Add class on sibling next to element

  7. 7

    Add class on sibling next to element

  8. 8

    XPath for next/sibling/following HTML element?

  9. 9

    Protractor - select next sibling of the current element

  10. 10

    Access next sibling <li> element with BeautifulSoup

  11. 11

    XPath for next/sibling/following HTML element?

  12. 12

    Style from next sibling element not work

  13. 13

    find an element inside an sibling of another element with jquery

  14. 14

    another jquery find next class not sibling for slideToggle

  15. 15

    Find next cell contained in sibling row with querySelector

  16. 16

    jquery .next can't find sibling

  17. 17

    using jquery next to find "nested" sibling

  18. 18

    Find next img element using known element id javascript/jquery

  19. 19

    Selecting Next HTML Sibling in Native Javascript

  20. 20

    Find preceding-sibling of the parent element in xslt

  21. 21

    how to get the next image tag after specific dom tag, sibling or not?

  22. 22

    Find next element in jquery

  23. 23

    Unable to find next element

  24. 24

    Get ID of next DOM element

  25. 25

    How to find and replace a string in HTML DOM element using javascript

  26. 26

    Javascript Quiz - problems reaching the next sibling through next() method on jQuery

  27. 27

    Select the next DOM element after the current element

  28. 28

    Inserting an element right after the sibling in Javascript

  29. 29

    Getting next sibling element using XPath and Selenium for Java

HotTag

Archive