0

How To Add Button in JS?

javascript form validation 😍

22nd Sep 2021, 3:13 AM
Shubham Bhatia
Shubham Bhatia - avatar
5 Antworten
+ 1
Use createElement()
22nd Sep 2021, 3:38 AM
Anurag Saikia
+ 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
22nd Sep 2021, 3:40 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Using script tag
22nd Sep 2021, 4:11 AM
Pariket Thakur
Pariket Thakur - avatar
+ 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.
22nd Sep 2021, 8:36 PM
Abdulrahman Muhammad
0
How to add script in html?
22nd Sep 2021, 3:58 AM
Shubham Bhatia
Shubham Bhatia - avatar