Wednesday, October 23, 2019

How can I convert a DOM element to a jQuery element?




I am creating an element with document.createElement().
Now how can I pass it to a function that only takes a Jquery object?



$("#id") 


I can not use it, as the element has not been rendered in the page yet.


Answer



var elm = document.createElement("div");
var jelm = $(elm);//convert to jQuery Element

var htmlElm = jelm[0];//convert to HTML Element

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...