Hi, How to create a div element in JQuery??
A:
Priyan R
2009-05-15 10:34:37
+8
A:
$("<div></div>").appendTo("div#main");
will append a blank div to <div id="main"></div>
Caius
2009-05-15 10:34:43
+4
A:
Hope this helps
div = $("<div>").html("Loading......");
$("body").prepend(div);
Ish Kumar
2009-05-15 10:36:29
+17
A:
First select the parent element with something like
$("#id"), $("<element>") or $(".class")
then use the .append("<div>foo</div>")
function. Alternatively, you can use the .html()
as mentioned above.
$("#foo").append("<div>hello world</div>")
cm2
2009-05-15 10:43:53
+13
A:
Technically $('<div></div>')
will 'create' a div element (or more specifically a DIV DOM element) but wont add it to your HTML document. You will then need to use that in combination with the other answers to actually do anything useful with it (such as using the append() method or such like).
The manipulation documentation gives you all the various options on how to add new elements: http://docs.jquery.com/Manipulation
samjudson
2009-05-15 10:49:01
how do you give your new div a new id? and say the id has to be dynamic? i.e '<div id=' + myNewId +'></div>'
towps
2010-06-07 15:53:09
use the .attr() method.
samjudson
2010-06-17 21:10:15