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

  • Home
  • SEARCH
  • 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 6343581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:28:01+00:00 2026-05-24T20:28:01+00:00

So I have a page that loads the data into the page through the

  • 0

So I have a page that loads the data into the page through the following ajax function.

$(document).ready(function(){             
                function loadData(page){                  
                    $.ajax
                    ({
                        type: "POST",
                        url: "inc/load_data.php",
                        data: "p="+page+"XXXXXXXXXXX",
                        success: function(msg)
                        {
                            //alert(msg);
                            $("#container").ajaxComplete(function(event, request, settings)
                            { 
                                $("#container").html(msg);
                                //**MODIFIED CODE
                                $(document).delegate('a.vote_up','click', f_vote_up);   
                            });
                        }
                    });
                }
  });

//Loaded Message

$msg.='<span class="vote_buttons" id="vote_buttons'.$row['id'].'">
       <a href="javascript:;" class="vote_up" id="'.$row['id'].'"></a>
       <a href="javascript:;" class="vote_down" id="'.$row['id'].'"></a>
    </span>';

The message that is loaded has some links that need to work with a another Ajax function(given below), which is apparently not working. The second function(below) is loaded before the data is loaded into the page. I suspect, may be since this function is loaded way before the data is loaded, the second function is not recognizing the click on vote_up. Is there any way to fix it??? I’m not too familiar with AJAX, I would really appreciate some help.. Thank you

$(function(){
    $("a.vote_up").click(function(){
    //get the id
    alert("Hi");
        //REST OF THE CODE
}

//***NEW FUNCTION

function f_vote_up(){
    //get the id
    the_id = $(this).attr('id');

    //REST OF THE CODE
    $("span#vote_buttons"+the_id).html("Hello, Testing Response!");
    alert("End of Func!"); // <
}
  • 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-24T20:28:02+00:00Added an answer on May 24, 2026 at 8:28 pm

    When you call that second function, it’s only grabbing all the a.vote_up elements that currently exist on the page. When you add more links to the page later on, they don’t know to listen for the click.

    You can do one of two things to fix this:

    1. Add the click listener to each new link when you add it to the DOM. But this is a bit of work, because you’d have to change how your AJAX function builds the links, and you’d have to turn that click-listener-assigning function into something standalone that you could use at any time.

    2. Instead of doing using the click method, use the delegate method instead:

      $(document).delegate('a.vote_up', 'click', function () { ... });
      

    More info on event delegation with jQuery.

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

Sidebar

Related Questions

I have a ChildUserControl that is loaded inside a ParentUserControl. The host page loads
I have the following Page_Load function... protected void Page_Load(object sender, EventArgs e) { XmlDataSource1.Data
I have a page that displays data from an object. I'm loading the object
I have a page that is generated which inserts an HTML comment near the
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when
I have a page that has an iframe From one of the pages within
I have a page that is hitting a webservice every 5 seconds to update
I have a page that is supposed to launch the Print Preview page onload.
I have a Page that has a single instance of a UserControl that itself
I have a page that contains a user control that is just a personalized

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.