Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Set an Attribute on an Element</title> </head> <body> <button type="button" id="myBtn">Click Me</button> <script> // Selecting the element var btn = document.getElementById("myBtn"); // Setting new attributes btn.setAttribute("class", "click-btn"); btn.setAttribute("disabled", ""); </script> </body> </html>