dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Wednesday Jul 10th 2019 by Srinath M S
Article Image

Language: Web, Expertise: Intermediate - Learn more about how to keep a reference to an HTML element and later add a few more properties to it in the script.

When you create a new HTML element, you may want to keep its reference and later add a few more properties to it in the script. Just store it in a var, and continue accessing it. See below for an example.

var myDiv = $("<div>Dummy Content</div>");


…

..


/*Later access the jQuery object with the var name and continue working with the object*/

myDiv.attr("id", "newlyCreatedDev");

myDiv.attr("class", "div mClass").appendTo("body");
Home
Mobile Site | Full Site