Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4325088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:13:13+00:00 2026-05-21T09:13:13+00:00

in a div, have elements (not necessarily 2nd generation) with attribute move_id . First,

  • 0

in a div, have elements (not necessarily 2nd generation) with attribute move_id.

First, would like most direct way of fetching first and last elements of set

tried getting first and last via:

var first = div.querySelector('[move_id]:first');
var last  = div.querySelector('[move_id]:last');

this bombs because :first and :last were wishful thinking on my part (?)

cannot use the Array methods of querySelectorAll since NodeList is not an Array:

var first = (div.querySelectorAll('[move_id]'))[0];
var last  = (div.querySelectorAll('[move_id'])).pop();

this bombs because NodeList does not have method pop()

(yes, one could could use Array methods on top of the NodeList:

var first = div.querySelector('[move_id]');
var last = Array.prototype.pop.call(div.querySelectorAll('[move_id']));

this works, and is what I’m using now, but thinking there has to be something more direct that I’m simply missing)

Second, need to verify that the elements are listed by pre-oder depth-first traversal as per http://en.wikipedia.org/wiki/Tree_traversal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:13:13+00:00Added an answer on May 21, 2026 at 9:13 am

    To access the first and last elements, try.

    var nodes = div.querySelectorAll('[move_id]');
    var first = nodes[0];
    var last = nodes[nodes.length- 1];
    

    For robustness, add index checks.

    Yes, the order of nodes is pre-order depth-first. DOM’s document order is defined as,

    There is an ordering, document order, defined on all the nodes in the document corresponding to the order in which the first character of the XML representation of each node occurs in the XML representation of the document after expansion of general entities. Thus, the document element node will be the first node. Element nodes occur before their children. Thus, document order orders element nodes in order of the occurrence of their start-tag in the XML (after expansion of entities). The attribute nodes of an element occur after the element and before its children. The relative order of attribute nodes is implementation-dependent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div which contains 2 elements. First element is a span and
I have a div called divContainer inside which i have few input elements like
Hi I have some elements like these: <div id=one>content</div> <div id=two>content</div> and a corrispondent
I have two div elements that are twins (i.e. their dimensions and contents are
I have two div -elements, the top one has the height of 40% and
I have several div elements for charts. Yslow is saying to reduce DOM elements.
I have some elements as below: <div id=shareswrapper> <div id=41> some content blah blah
Lets say I have a div #elements with a ul inside.The div has position:
So I have a div with some child elements and when I select one
I have the following elements in a HTML page: <body> <div style=height:100%; width:100%> <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.