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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:56:29+00:00 2026-05-18T00:56:29+00:00

Using Javascript I’m trying to test whether or not a DIV with the id

  • 0

Using Javascript I’m trying to test whether or not a DIV with the id “test_div” exists in the document.

I’m using

if (getElementById("test_div"))

in the below script to check if the DIV exists in the document. However it does not work. I don’t have very much experience with Javascript; but from the research I have done it seems like my problem might have something to do with the nested function.

The script does work if I remove the

if (getElementById("test_div"))

Does anyone know how to check if a DIV with the id “test_div” exists in the document from within the function as shown below?

<div id="test_div"></div>

<script>
function loadInfo(){
var req = new Request({
    method:'get',
    url:'getinfo.php,
    noCache: true,
    onRequest: function(){

        if (getElementById("test_div")) {
            $('test_div').set('html', 'loading data');
        }

    },  
    onComplete:function(responseText, responseHtml){
        if (JSON.decode(responseText) != null){
            var data = JSON.decode(responseText);

            if (getElementById("test_div")) {
                $('test_div').set('html', data['test_div']);
            }

        }   
    },
    onFailure: function(){

        if (getElementById("test_div")) {
            $('test_div').set('html', '-');
        }

    }           
}).send();  
}
window.addEvent('domready', function(){
loadInfo();
});
</script>
  • 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-18T00:56:30+00:00Added an answer on May 18, 2026 at 12:56 am

    You would have to do document.getElementById(id). But seeing how you are using jquery – you could also do $(id).length > 0 to check if the element exists

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

Sidebar

Related Questions

Using JavaScript, is there a way to detect whether or not an external script
Using javascript I'm trying to load images not on the current page (from an
Using JavaScript I'm trying to split a paragraph into it's sentences using regular expressions.
Using Javascript or jQuery, how can I check if an external link is available?
Using Javascript, how can I access a specific child of a row? Javascript (not
Using JavaScript, how do I NOT detect 0, but otherwise detect null or empty
Using javascript, I am trying to change the selection of the listbox item like
Using JavaScript, I need to check if a given string contains a sequence of
Using JavaScript, how can I determine the size of an image which is not
Using Javascript. I'm trying to loop through an array encoded with JSON. Here is

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.