0

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 Answers 2

2

Why dont you do it all in query...

$('#menu').html(menuHtml); $('ul.sf-menu', menuHtml).superfish(); 
Sign up to request clarification or add additional context in comments.

2 Comments

$('#menu') also doesn't find anything - no idea why, document.all("menu") works fine.
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.
0

is your code wrapped in a document ready event?

$(document).ready(function() { // put all your jQuery goodness in here. }); 

1 Comment

Nope, its on the HTTPReadyStateChange of an xmlHttp request though, if it makes any difference.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.