0
How To Add Button in JS?
javascript form validation 😍
5 Respuestas
+ 1
Use createElement()
+ 1
Do u want to say
How to add button using JS
It's easy using createElement
+ append
The Element.append() method inserts a set of Node objects or DOMString objects after the last child of the Element. DOMString objects are inserted as equivalent Text nodes.
For example we create a button
var btn = document.createElement("button")
Now this will not work until we append btn
document.append("btn")
Congrats we create a button
for more information visit
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
+ 1
Using script tag
+ 1
You can create a button in HTML and use DOM to manipulate it with javascript
E.g on the html
<button onclick = "printMessage()">Print Message</button>
And on the JavaScript you use
Function printMessage (){
let message = "Hi"
alert(message)
}
//This will return hi on the browser if you click the button.
0
How to add script in html?