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
  • 1 View
  • 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 class=city> <div class=a>Delete</div> <div class=b>Selected</div> <div class=c>Delete</div>
I have the following dom structure: <div class=ui-tabs> <ul> <li class=ui-state-default ui-tabs-selected ui-state-active> <a
I have the following DOM: <div class=qtip qtip-light qtip-active> <div class=qtip-wrapper> <div class=qtip-borderTop></div> <div
If I have the following DOM elements <div class=item>content1</div> <div class=item>content2</div> how, using jQuery
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 elements: <div class=document> <div class=text> some text1 </div> <div
I have a DOM structure like the following: <table class=playlist> <thead> <tr> <th>TH1</th> <th
I currently have the the following HTML structure: <div class=article-preview> <h1><a href=>Title</a></h1> <a class=pic-link
Suppose I have the following DOM : <div id=container> <div id=created-by-other-tools>I want this to

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.