0
How to create a new html element in javascript?
I want to make a function where a new html element is created like a paragraph/div/list or anything i want. For example user presses a button and onclick i add the function. Then the function adds an html element to the code. How to make this happen
6 Answers
+ 2
var p = document.createElement("p");
var node = document.createTextNode("Some new text");
//adding the text to the paragraph
p.appendChild(node);
anything.append(p);
anything is the place where you want To put your paragraph
+ 1
var anything is not defined in this case, but Yes if you assosiate it with an element of DOM.
0
This is covered in this course:
https://www.sololearn.com/Course/JavaScript/
0
https://www.sololearn.com/learn/JavaScript/2755/
0
Saad Mughal how do i give the element i just created an id?
0
p.id = "Name";
I think like this we can set Id not sure try this
Here p is a variable you created