HTML content modification using Javascript
JavaScript is the dynamic, lightweight and most commonly computer programming language used to create a web pages. It interact with client side and make dynamic pages.
JavaScript Can Change Content of HTML page: The getElementById() method is used to get the id of element and change the HTML content.
Example:
<!DOCTYPE html> <html> <head> <title> Change HTML Content using Javascript </title> </head> <body> <h1> GeeksforGeeks </h1> <h2> Change HTML Content using Javascript </h2> <p id="GFG"> GeeksforGeeks: A computer science portal </p> <button type="button" onclick= 'document.getElementById("GFG").innerHTML ="Welcome to GeeksforGeeks"'> Click Here! </button> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

JavaScript Can Change Styles of HTML page: JavaScript can be used to change the CSS property of HTML page.
Example:
<!DOCTYPE html> <html> <head> <title> Change HTML Content using Javascript </title> </head> <body> <h1> GeeksforGeeks </h1> <h2> Change HTML Content using Javascript </h2> <p id="GFG"> GeeksforGeeks: A computer science portal </p> <button type="button" onclick= "document.getElementById('GFG').style.fontSize= '25px'"> Click Here! </button> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

JavaScript Can Hide or Show HTML Elements: JavaScript can be used to change the display property to hide or show element content.
Example:
<!DOCTYPE html> <html> <head> <title> Change HTML Content using Javascript </title> </head> <body> <h1> GeeksforGeeks </h1> <h2> Change HTML Content using Javascript </h2> <p id="GFG"> GeeksforGeeks: A computer science portal </p> <button type="button" onclick= "document.getElementById('GFG').style.display= 'none'"> Click Here! </button> </body> </html> |
- Output before clicking:

- Output after clicking:

Recommended Posts:
- How to clear the content of a div using JavaScript?
- How to print the content of an object in JavaScript ?
- Print the content of a div element using JavaScript
- How to change the Content of a <textarea> using JavaScript ?
- Adding HTML entities using CSS content
- How to insert HTML content into an iFrame using jQuery?
- How to determine the content of HTML elements overflow or not ?
- Search Bar using HTML, CSS and JavaScript
- JavaScript | JSON HTML
- Where to put JavaScript in an HTML Document ?
- Validate a password using HTML and JavaScript
- Form validation using HTML and JavaScript
- How does inline JavaScript work with HTML ?
- How to remove an HTML element using JavaScript ?
- How to append HTML code to a div using JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



