[Vuejs]-How does jQuery create DOM elements from string?

0👍

Basically, jQuery uses RegExp and other tricks to parse the relevant parts from the string. For the example you gave, it would get an element of type div with a class attribute that has a value of foo.

Then it uses that data to create the element and add the properties corresponding to the attributes:

var element = document.createElement("div");
element.className = "foo"; // className is the DOM property equivalent to the class attribute

And that’s it for this particular example, since the element doesn’t have any child elements indicated by the HTML string

Leave a comment