Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- var x2 = "My First JavaScript Function";
- var x1 = "Button 1";
- function myFunction()
- {
- var current = getHtml("test");
- setHtml("test", current == x1 ? x2 : x1);
- }
- function getHtml(id) { return document.getElementById(id).innerHTML; }
- function setHtml(id, text) {
- document.getElementById(id).innerHTML = text;
- }
- </script>
- </head>
- <body>
- <h1>My Web Page</h1>
- <p id="test">Button 1</p>
- <button type="button" onclick="myFunction()">Try me</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment