2

I am using a cms which has a page where new content is added via ajax.

So the content is constantly updating but there are no page refreshes.

This is typically the html for each piece of content which gets added.

   <li class="row-1" style="display: block;">
       <div class="content">
           Body text for content 1
       </div>
   </li>

As more content gets added the html will look like

    <li class="row-2" style="display: block;">
       <div class="content">
            Example text for content 2
       </div>
    </li>
    <li class="row3" style="display: block;">
       <div class="content">
            some more example text for content 3
       </div>
    </li>

etc

On my page load I have jquery being executed for the content which is already existing.

What I would like is jquery to be executed for each new content as it gets loaded on to the page.

Would I create the jquery individually for each item, then load the jquery when each item gets added to the page.

Or would I create a jquery function which detects when new content is added?

For now to begin with I would just like to alert when new content gets added so I can see how it is done?

Thank you for reading and any help provided.

Sam Healey
  • 666
  • 2
  • 8
  • 22
  • please add your ajax response code. – Jay Shukla Jul 26 '13 at 11:08
  • I guess you have to do something with `setInterval` and check your database to see if there is new content added. – putvande Jul 26 '13 at 11:09
  • As far as I understand your problem, your content is added by using ajax. That means, you will have some ajax call which will have success callback, which eventually binds data to the page. Then in that success callback function you can bind your jquery code for the new content. Correct me if I am not getting scenario right. – GirishK Jul 26 '13 at 11:18

1 Answers1

0

Check answer to this SO question that could be a solution to bind the event on successful ajax load.

This might be the way you want to go for your website.

So what you can do is load the jquery with the elements itself and bind events to these elements.

Community
  • 1
  • 1
Harshad
  • 570
  • 1
  • 3
  • 17