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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:48:16+00:00 2026-06-18T01:48:16+00:00

Possible Duplicate: Use variable outside the success function from an ajax/jquery call I have

  • 0

Possible Duplicate:
Use variable outside the success function from an ajax/jquery call

I have this code and i don’t understand why the accessing of the html elements is only working inside the ajax success function. the form is pulled in from ajax either way but i can only access it when i put all the selects for elements of it inside the ajax function.

The console.log('submit clicked'); gets not triggered this way, but inside the “ajax success” it does, i thaught everything pulled in with ajax is part of the DOM?

jQuery(document).ready(function($) {

console.log('ready');

$.ajax({
    type: 'GET',
    url: 'admin-ajax.php',
    data: { action: 'get_arve_form' },
    success: function(response){
        // var table = $(response).find('table');
        $(response).appendTo('body').hide();
        console.log('response');

                    [ if i move the code below this ajax function in here its workign fine why not outside of it?]

    }
});

// handles the click event of the submit button
$('#mygallery-submit').click(function(){
    console.log('submit clicked');
                [...]
        });
  • 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-18T01:48:17+00:00Added an answer on June 18, 2026 at 1:48 am

    Ajax is asynchronous so your elements don’t exist until the ajax call finishes.

    That being said, there are two ways to fix it:

    1) Move your code into the success handler

    2) Use event delegation to bind your event handler to all current and future elements.

    An example of #2:

    $(document).on('click', '#mygallery-submit', function(){
        console.log('submit clicked');
    });
    

    Check out jQFundamentals to learn more about event delegation.

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

Sidebar

Related Questions

Possible Duplicate: How to use include within a function? i have two file inc.php
Possible Duplicate: JavaScript: string contains I have a postcode variable and want to use
Possible Duplicate: JavaScript Variable Scope I have a JavaScript function for HTML select options
Possible Duplicate: Use a variable within a variable? Java Hi this is a general
Possible Duplicate: Use a variable to define a PHP function Is there a way
Possible Duplicate: Use of .apply() with 'new' operator. Is this possible? I have 5
Possible Duplicate: How to use javascript variables in jquery selectors This works $('input[name=nickname]').css(...); Now
Possible Duplicate: What's an actual use of variable variables? OK, this question may look
Possible Duplicate: Accessing inherited variable from templated parent class I have been implementing a
Possible Duplicate: PHP: Variable in a function name I have some functions and i

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.