I herd you like divs

Loading a div content with ajax

While I was working on two personal websites (raspy.wuww.org and wuww.org/mc) I’ve found the need to dinamically reload a div content without reloading the entire page.
Guess what, jQuery got something for it, and it’s the .load() function.

Well, .load() by itself didn’t work as I expected because it’ll load the entire thing and cause a “Yo Dawg i herd you like divs so we put a div in yo div” effect that I didn’t want.

After a while on Stack Overflow I’ve found the droids… ehm page I was looking for, but the most upvoted answer isn’t the one that actually works for me, and that sucks… but! at #4 here it is, and in hope to help all of you that are searching for this I’ll report the code here 😉


$(‘#div’).load(“page.html #div”, function() {


All you’ve to do is to replace the #div with the element you want to reload, and the page.html is just the source of that div (and it could be the same page you are at now) and that’s all.