HomeLanguagesJavascriptHTML content modification using JavaScript

HTML content modification using JavaScript

JavaScript is the dynamic, lightweight, and most common computer programming language used to create web pages. It interacts with client-side and makes dynamic pages. JavaScript Can Change the Content of an HTML page. The getElementById() method is used to get the id of the element and change the HTML content. 

Example: In this example, we will change the content of the paragraph element.

html




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible"
          content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>
        Change HTML Content using JavaScript
    </title>
</head>
 
<body>
    <h1 style="color:green;">
        neveropen
    </h1>
 
    <h3>
        Change HTML Content using Javascript
    </h3>
 
    <p id="GFG">
        neveropen: A computer science portal
    </p>
 
    <button type="button" onclick=
        'document.getElementById("GFG").innerHTML
            ="Welcome to neveropen"'>
        Click Here!
    </button>
</body>
</html>


Output:

HTML content modification using Javascript

HTML content modification using JavaScript

JavaScript Can Change Styles of the HTML page: JavaScript can be used to change the CSS property of an HTML page. 

Example: In this example, we will change the style of the paragraph element.

html




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible"
          content="IE=edge">
    <meta name="viewport" content= "width=device-width, initial-scale=1.0">
    <title>
        Change HTML Content using JavaScript
    </title>
</head>
 
<body>
    <h1 style="color:green">
        neveropen
    </h1>
 
    <h3>
        Change HTML Content using Javascript
    </h3>
 
    <p id="GFG">
        neveropen: A computer science portal
    </p>
 
    <button type="button"
        onclick="document.getElementById('GFG')
            .style.fontSize='25px'">
        Click Here!
    </button>
</body>
</html>


Output:

HTML content modification using Javascript

HTML content modification using JavaScript

JavaScript Can Hide or Show HTML Elements: JavaScript can be used to change the display property to hide or show element content. To understand this feature refer to this Hide or show elements in HTML using display property article

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6922 POSTS0 COMMENTS
Nicole Veronica
12037 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12143 POSTS0 COMMENTS
Shaida Kate Naidoo
7057 POSTS0 COMMENTS
Ted Musemwa
7298 POSTS0 COMMENTS
Thapelo Manthata
7015 POSTS0 COMMENTS
Umr Jansen
7001 POSTS0 COMMENTS