i’m pretty new to jquery. I’m trying to insert an element to the DOM, and get that element back in my script.
Ex:
var elem = $("body").append("");
$(elem).show();
but it seems that .append returns the whole jQuery object..
am i supposed to use an ID for the inserted element and always reference it by it?? i really hope that there is a smarter move here.
I’m used to do it like that from Prototype..
Let’s suppose you want to create a
div:The above code create the
div, sets some html for it usinghtml()and hides it initially on because later you want to show it.Note: Note that I have written different methods/functions on the same line, this is known as chaining in JQuery and yes very useful.