Jump to content

reloading content in a div


acidglitter

Recommended Posts

I have my regular php page, and it has a div. What I want to happen is when you click a link, the content inside the div is refreshed (the content gets reloaded). If I have the link outside of the div (on the php page), the refresh link works fine. But if I put the link inside the div (so it's part of the loaded content) it doesn't work. I'm using jQuery so my refresh link looks like this..

 

<a href="" id="refreshpage">refresh</a>

 

The actual script is like

 

$("#refreshpage").click(function(){
$("#box").html('<p>loading..</p>');

$.get("page", function(loadthis){
	$("#box").html(loadthis);
});

return false;
});

 

Why doesn't the link work when it's part of the loaded content? Is it only because I'm using jQuery?

Link to comment
Share on other sites

If you have a click event listener attached to the div instead, and then get the target of the event making sure to look for the element id of refreshpage, you wouldn't have to make a new event listener each time the div is loaded.

 

To recap, the click event listener on the div would fire any time the div is clicked, but you would check the target of the click to make sure that it was the link that was clicked, and not something else inside the div. And then you can proceed to reload the div that way.

 

Hope that helps...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.