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

  • Home
  • SEARCH
  • 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 502629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:18:39+00:00 2026-05-13T06:18:39+00:00

I have the following DOM structure: /*:DOC += <div id=’testDiv’ class=’testDivClass’><div id=’innerTestDiv’></div></div><span id=’testSpan’ class=’testSpanClass’><span

  • 0

I have the following DOM structure:

/*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span id='innerTestSpan'></span></span>

Now I tried to run jQuery select against them as follow. The first one returned alright, but the second one failed:

// works
var result = $('#testDiv')[0];
alert(result.id);

// failed: id is null or not an object
var result2 = $('#testSpan')[0];
alert(result2.id);

I tried selecting id instead of class and got the same results.

My question is: how can I get the second select to work? Is there some sort of invisible iterator/pointer in jQuery which I need to reset to the beginning of the DOM before the second select?

Thanks.

EDIT: Ok this is the official “does not work” version. testDiv matched, but testSpan did not, hence I got an error saying id is null or not an object error in the second alert.

UPDATE: I did a test by swapping testDiv and testSpan in the html. Now BOTH select failed.

UPDATE2: I have changed the html back to what it used to look like. I’m using JsTestDriver to write up the test, but it is actually not calling anything at the moment. The actual html looks messier than this (more nested tags). I’m trying to get this simplified version to work first. It appears that jQuery was able to get into the first select, whether it’ll be span or div, but couldnt get out of it to do the second select. I’ve replaced jQuery.js and jsTestDriver.jar to no avail.

Thanks.

  • 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-13T06:18:39+00:00Added an answer on May 13, 2026 at 6:18 am

    What I ended up doing is wrapping the entire html with a div or span tag. I found that jQuery could not get out of a div/span tag once it gets into one (in my above example), so I just make it to go into a div/span tag once.

    Not sure whether this is a patch or ugly fix, but it solved my problem for now.

    Thanks for all the help!

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

Sidebar

Related Questions

I have the following DOM structure: <div id=module-main> <div id=module-crumbs> <h4>Hello</h4> </div> </div> When
I have the following structure: <form> <div class=content> ... </div> <div class=action> <p>Select <a
I have the following DOM structure.. <input id=WorkAssignmentID_3462 type=hidden value=3462 name=WorkAssignmentID/> <input id=WorkItemID_3462 type=hidden
I have the following DOM structure (unordered list), that I would like to sort
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
I have the following link which opens a dom window... <a href='#inlineContent' class='defaultDOMWindow'>(edit interests)</a><br
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have following classes. class A { public: void fun(); } class B: public
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.