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 909279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:51:08+00:00 2026-05-15T16:51:08+00:00

Is it possible, in either the jQuery API or the DOM, to check if

  • 0

Is it possible, in either the jQuery API or the DOM, to check if an element exists on the page or not?

Consider these two variables:

var selected = $('span#mySpan');
var created = $('<span id="mySpan">Testing</span>');

Both will return a jQuery object containing a span element. Is there any way to tell that the first exists on the page, and the second one does not?

  • 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-15T16:51:09+00:00Added an answer on May 15, 2026 at 4:51 pm

    Try

    $(created).parents("html").length
    

    Here are some more ways to do the same:

    $(document).find(created).length
    $(created).parents(document).length
    

    Or using the contains method that was built for this task. It only accepts DOM nodes, so we need to unwrap it from the jQuery object

    $.contains(document, created.get(0))
    

    A pure DOM way will be to use the Node.compareDocumentPosition method. In the above example,

    // get the DOM node
    var createdNode = created.get(0);
    var position = document.compareDocumentPosition(createdNode);
    var isNotInDocument = (position & Node.DOCUMENT_POSITION_DISCONNECTED) != 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to open a select element using jQuery? Either that or prevent
Is it possible, using Javascript and either jQuery or regular expressions, to group multiple
Using either JavaScript or jQuery, is it possible to capture a count on an
Using either JavaScript or jQuery, is it possible to capture a count on an
Is it possible for jQuery to work with partial elements (aka ranges)? Probably not,
When calling page methods or web services with either jquery or MSAjax, the Session
Possible Duplicate: Using jQuery to compare two arrays I need a Javascript or jQuery
Is it possible with only one bind to either keyup , keypress or keydown
Is it possible to specify connection/query timeout for the Oracle database queries? Either on
Possible Duplicate: check whether internet connection is available with C# I just want 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.