I want to create a div and append one ul (with a class) and one h5 (with text) to it. then, append that div to another element.
I think this code should do it:
$("div").addClass( "nice" )
.append( $("ul").addClass("myclass") )
.append( $("h5").text("heading") )
.appendTo( $("#another_div") );
but it doesn’t work and browser crashes!
How? (i know i can use $("div").html(), but i don’t like it!)
Thank you.
Your problem is that by using “div” and “ul” as your selectors, jQuery is searching the dom instead of creating elements. Try this: