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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:46:35+00:00 2026-05-28T03:46:35+00:00

I have a jquery script which runs when the document is ready. It appends

  • 0

I have a jquery script which runs when the document is ready. It appends each of the existing elements “div.cool” with the text “[hi]” at the end.

Then I have an ajax script which loads new elements. When new elements are added with the class “div.cool”, the jquery script doesnt append them.

What can I do to run the script when new elements are created?

Example:

http://jsfiddle.net/csDyM/3/

HTML:

<div class="container">
    <div class="cool">some text.</div>
    <div class="cool">some text.</div>
    <div class="cool">some text.</div>
    <div class="cool">some text.</div>
</div>

<a href="#_" onclick="loadmore();">ajax more</a>

Javscript:

$(document).ready(function() {
    $("div.cool").append("[hi]");
});

function loadmore () {

    // this for loop represents the ajax dynamic content. it cannot be changed. 
    for (i=1;i<=4;i++) {
        $("div.container").append('<div class="cool">some text.</div>');
    } 

     // $("div.cool").append("[hi]"); adding this works but it appends existing elements
}

The AJAX (replaced with for loop in exapmle):

$.ajax({
    url: http://url.com/file.php,
    cache: false,
    success: function(html){
        $("div.container").html(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-05-28T03:46:36+00:00Added an answer on May 28, 2026 at 3:46 am

    You could add a trigger class and test against it:

    http://jsfiddle.net/euBYj/

    $(document).ready(function() {
        $("div.cool").append("[hi]").addClass("skip");
    });
    
    
    function loadmore () {
    
        for (i=1;i<=4;i++) {
            $("div.container").append('<div class="cool">some text.</div>');
        } 
    
        $("div.cool:not(.skip)").append("[hi]").addClass("skip");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have a jQuery Dialog which initializes hotkeys as follows: <script type=text/javascript> $(document).bind('keydown', '<%=(i+1)%>',function
I have this jquery script which suppose to hide/show div element base on the
i have some jquery script which runs after the window has loaded $(window).load( function()
I have a jQuery script which returns the current date into a text box.
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I'm trying to update some existing code that normally runs a Perl script which
I have a JQuery script which acts as a simple image rollover with a
I have taken a jQuery script which would remove divs on a click, but
I have a jquery script which I need to run only once everything else

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.