Geekality

Geekality

Search
Skip to content
  • About Me
    • The website
    • Curriculum Vitae
  • Programming
    • My journey into computing
Software Development

Javascript: Index of node within parent

October 31, 2017 Torleif Leave a comment

Apparently isn’t any node.index property built-in, so here’s how to find it, in case I need it again:

function indexOf(node)
{
    let i = 0;
    while(node = node.previousElementSibling) i++;
    return i;
}

Source: StackOverflow

DOMHTMLJavascript

Post navigation

Previous PostWindows 10 Default app removalNext PostHow to repair broken user folders in Windows

Greetings! I am Torleif Berger, and I’m a Software Engineer. I’m a Seventh-Day Adventist, an introvert, an ISFJ-T, and an HSP. Currently into forest hikes and indoor rock climbing; also dabble a bit with indoor rowing, juggling, and other fun activities, but most of my time is spent in front of a screen… c”,)

Stack Overflow

Google Twitter Facebook LinkedIn YouTube Vimeo RSS

Recent Posts

  • Enable SQL logging in Play 2.5+
  • JavaScript: In-browser export to CSV
  • Minecraft: Remove invisible Roots 2 mob spawner
  • Round number to nearest multiple
  • Fix IntelliJ Alt Gr not working
  • Javascript: Count number of lines in a string
  • Git: How to fully clean a working directory

Categories

Archives

Creative Commons License

With a hint of Social Ineptitude

Proudly powered by WordPress