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
https://forums.phpfreaks.com/topic/150503-reloading-content-in-a-div/
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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.