I am trying to refresh a certain part of my page with AJAX and JQuery (in Django). How can I get it to redisplay only the div, rather than the whole page.
Use load:
$('#tag_cloud').load(' #tag_cloud')
(Note the leading space in the load
parameter; this specifies an empty string [which evaluates to the current page] as the source, and "#tag_cloud" as the fragment to load)
This will actually load #tag_cloud (including its outer html) into #tag_cloud, so you'll essentially get the following structure in your DOM:
tag ...
To fix this, just unwrap
the children:
$('#tag_cloud').load(' #tag_cloud', function(){$(this).children().unwrap()})
Oh, by the way... you can try this here on SO! Just paste the following into your Firebug console, and watch the sidebar auto-reload. You'll notice some scripting code poking through; that's jQ's HTML-safety filters disabling the
elements for you (which can be annoying at times).
$('#sidebar').load(' #sidebar', function(){$(this).children().unwrap()})