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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:01:17+00:00 2026-05-31T12:01:17+00:00

I am having this function in jQuery where I’m getting new posts with AJAX

  • 0

I am having this function in jQuery where I’m getting new posts with AJAX and PHP. And then creating a new div and appending the post to it.

Here is my code:

function getMorePosts(latestPost){

    $.ajax({
        type: "POST",
        url: "/includes/classes/handler.php?do=getMorePosts",
        data: "&latestPost="+latestPost,
        cache: false,
        success: function(data){
            if(data){
                $('#addUpdate textarea').val('');
                $('<div id="newPosts"></div>').insertAfter('.myDeskAdd');
                $(data).prependTo('#newPosts');
            }
        }
    });
    return false;
}

Now, data is all of HTML code from my handler.php. Everything works, it’s appending and I can see the result on the screen. And it’s correct – nice!

But here is my problem:
When it’s added to the screen, it’s like I cant ‘use’ the DOM elements. For example: I have an image which I can click, and then it has to call an alert from jQuery, but it’s not. And all other jQuery effects bound to the dom elements created doesn’t work.

Those elements not working DOES work if I press F5.

I have tried html(), prepend(), append() and so on.

  • 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-31T12:01:18+00:00Added an answer on May 31, 2026 at 12:01 pm

    for all dynamic content (loaded from ajax), bind methods using jQuery on. Then it should work

    instead of this,

     $(".imageClass").click(function(){
        alert($(this).html());    
     });
    

    Use this

     $(".yourContainerDiv").on("click", ".imageClass", function(event){
         alert($(this).html());    
     });
    

    http://api.jquery.com/on/

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

Sidebar

Related Questions

Having multiple event handlers on a jQuery .on() method, like this: $(div.test).on({ mousemove: function(e){
I have this function after an ajax post. success: function(){ window.location = 'morefive.php?document=' +
$('form').submit(function(){ this.action=http://www.sitename.com/post; return false; }); having altered the action attribute of the form ,i
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
I'm having a problem with this jQuery function, the portion of the function that
Having trouble with this jQuery function: $(#content).siblings().each(function(i){ heightOfSiblings = heightOfSiblings + this.outerHeight(); }); Error
I'm having a few issues getting a simple JQuery function to work that fades
I have a php function which is called by a jquery function. This jquery
Im having this function to determine weather a user exists in a database or
I am having a JavaScript namespace say A={ CA: function() { this.B(); }, B:

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.