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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:52:01+00:00 2026-05-30T04:52:01+00:00

I loaded the following HTML via Ajax into a web page powered by jQuery

  • 0

I loaded the following HTML via Ajax into a web page powered by jQuery Mobile. What’s important is the class name of onButton attached to the anchor tag.

<a class="onButton ui-btn ui-btn-inline ui-btn-corner-all ui-shadow ui-btn-up-c" href="#" data-role="button" data-inline="true" data-theme="c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Turn On</span></span></a>

After loading via Ajax, I triggered a “create event” to apply jQuery Mobile button styles per the documentation.

$.ajax({
    url: '/loadAllButtons',
    context: $('contentBox'),
    cache: false,
    data: {'listOfEntities': JSON.stringify([1,2,3,4,5])},
    success: function(data) {
        $(this).html(data).trigger( "create" );
    }
});

I see that the buttons have been successfully loaded. However, when I call console.log($('.onButton').length);, the console displays 0.

That is interesting because Chrome Web Developer notes 5 instances of <a> tags with the onButton class loaded via Ajax.

Why is jQuery not detecting the newly loaded anchor tags (or buttons)?


To be clear, here is how I am debugging:

$.ajax({
    url: '/loadAllButtons',
    context: $('contentBox'),
    cache: false,
    data: {'listOfEntities': JSON.stringify([1,2,3,4,5])},
    success: function(data) {
        $(this).html(data).trigger( "create" );
    }
});
console.log($('.onButton').length);

Thank you.

  • 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-30T04:52:02+00:00Added an answer on May 30, 2026 at 4:52 am

    You need to put your debugging console.log() in the callback for the AJAX call. As it is, the console.log() is running just after the request is sent (since by default AJAX requests are asynchronous), which will be before the response is received from the server and therefore before any elements have been added to the DOM.

    Try this:

    $.ajax({
        url: '/loadAllButtons',
        context: $('contentBox'),
        cache: false,
        data: {'listOfEntities': JSON.stringify([1,2,3,4,5])},
        success: function(data) {
            $(this).html(data).trigger( "create" );
            console.log($('.onButton').length);
        }
    });
    

    Also, since you are adding button elements to the DOM that already have the jQuery Mobile classes/structure applied, you may need to call .button('refresh') to refresh the elements instead of .trigger('create') to initialize them. I haven’t used .button('refresh') before so I’m not sure if you can call it on an ancestor element of the buttons or if you have to call it on the buttons themselves like:

    $(this).html(data).find('.onButton').button( "refresh" );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html code: (that gets loaded via ajax into a div)
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
In a page that has a grid/list dynamically loaded via AJAX, an efficient way
I have the following in web layout (master page): @(Html.Telerik().ScriptRegistrar() .DefaultGroup(group => group .DefaultPath(~/Assets/telerikaspnetmvc/2011.2.712/Scripts/)
I'm using the jQuery UI Tabs plug-in to load html pages via ajax, so
I have a template loaded via ajax and template contains the following lines: <script
I'm using the following script to force a specific page - when loaded for
I have the following Javascript code. When the page is loaded it is scrolled
i have the following lines of html code - <div class=twitters id=cbd> <p><a href=javascript:;
I have the following structure: -uploadpage.html -index.php -resources -jquery-1.4.2.min.js On my index.php, I get

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.