tags:

views:

33

answers:

2

I'm trying to dynamically set the contents of a div on my page and then call a Jquery method, ala:

document.all("menu").innerHtml = menuHtml;
$('ul.sf-menu').superfish(); 

However the $('ul.sf-menu') part of the above fails to find any elements (menuHtml does definitely contian a <ul /> with class sf-menu)

I'm very new to jquery and I'm struggling to understand why this fails to find my newly added element. Is it because its been dynamically added to the DOM, or is it that jquery isn't searching "everywhere"?

+2  A: 

Why dont you do it all in query...

$('#menu').html(menuHtml);
$('ul.sf-menu', menuHtml).superfish();
prodigitalson
`$('#menu')` also doesn't find anything - no idea why, `document.all("menu")` works fine.
Kragen
Aaaah - sorry I take it all back, `$('#menu')` does find my element - using jquery to set the contents successfully updates the DOM and means the next statement works fine - thanks.
Kragen
A: 

is your code wrapped in a document ready event?

$(document).ready(function() {
   // put all your jQuery goodness in here.
});
PetersenDidIt
Nope, its on the HTTPReadyStateChange of an xmlHttp request though, if it makes any difference.
Kragen