user656925
user656925

Reputation:

Traversing the DOM

I have some bookmarks that are displayed as pages. I need to search these pages for a particular page in this case - page with id "social_page".

So to start, I grab the containing div

var bookmark_fill = document.getElementById( 'bookmark_fill' );

How do I best traverse the "pages" in bookmark_fill? This simple case below has only 2 pages.

enter image description here

Upvotes: 1

Views: 294

Answers (2)

Adam Rackis
Adam Rackis

Reputation: 83358

To get your bookmark_fill node:

var bookFill = document.getElementById("bookmark_fill");

To get all the pages in there, you can use the getElementsByClassName method

var allBookMarkPages = bookFill.getElementsByClassName("bookmark_page");

for (var i = 0, max = allBookMarkPages.length; i < max; i++) {
    var allLinks = allBookMarkPages[i].getElementsByClassName("bookmark");
}

Upvotes: 1

Joseph Marikle
Joseph Marikle

Reputation: 78520

var socialPage = document.getElementById("social_page");

because ID's are supposed to be unique.

Upvotes: 4

Related Questions