dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Create an HTML Element and Hold it in a Reference Variable

Learn more about how to keep a reference to an HTML element and later add a few more properties to it in the script.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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");

 

Visit the DevX Tip Bank

 





   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Thanks for your registration, follow us on our social networks to keep up-to-date