0
Creating elements Dom node
Every tags are nodes. I understand like that. But my doubt is where should I use it. And why should I change elements and attributes of the documents.. ? Or Is the way of javascript we must know ..
1 Réponse
0
You'll want to manipulate the document to output virtually anything to it. This could be through innerText instead of creating new Element and other nodes, though.
Binding event listeners to elements in the document never requires creating new nodes but it will require searching the document for them. Binding events is also frequently needed so your functions get called when you want them to and you can interact with the user.
Very commonly, if I use JavaScript I'll at least bind some event handlers to elements in the document and output results through an Element's innerText. Client side validation commonly works this way.
Creating new elements is less common in vanilla JavaScript. I'd use a single page application framework or library if extensive dom manipulation is needed. Even jQuery leads to cleaner dom manipulation code than things like "document.createElement" or assigning to innerHTML.