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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:16:58+00:00 2026-06-10T20:16:58+00:00

jQuery is not finding any elements. alert($(#testbutton).length); displays 0 every time. Am I doing

  • 0

jQuery is not finding any elements. alert($("#testbutton").length); displays 0 every time.

Am I doing something wrong?

My JS / jQuery code:

(function ($) {
    alert($("#testbutton").length);
}) (jQuery);

My HTML:

<html>
    <body>
        <div id="header">
            <div class="button" id="testbutton">Test</div>
        </div>
    </body>    
</html>
  • 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-06-10T20:16:59+00:00Added an answer on June 10, 2026 at 8:16 pm

    When your code runs the DOM is not ready so the element doesn’t exist. Did you mean to do this instead (passing a function to jQuery is a shortcut for $(document).ready(fn)):

    $(function () {
        alert($("#testbutton").length);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my jquery code not run with IE6 but runs all others including IE7. It
Why is my jQuery code not increasing the font size? <!DOCTYPE html PUBLIC -//W3C//DTD
I've been searching around this morning and I'm not finding any simple solutions... basically,
Hilariously, I'm having incredible difficulty finding any half-good way to determine whether or not
Just tried out the following approach finding that this does not work? (Using jQuery):
Problem Scripts on some pages that use jquery are not activating. Scenario Finding that
I could not be any more brand-spanking new to Titanium, so even finding the
Trying to wrap my head around the jQuery .not() function, and running into a
this is the problem: I'm using javascript and JQuery (not UI) to drag nested
Jquery does not work on the Internet explorer . However it runs on other

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.