loading

JS Introduction

JavaScript Can Change HTML Content

GetElementById() is one of multiple JavaScript HTML methods.

The following example “finds” an HTML element (with id=”demo”) and modifies its innerHTML content to “Hello JavaScript”:

Example

				
					document.getElementById("demo").innerHTML = "Hello JavaScript";
				
			

JavaScript supports single quotes as well as double quotes:

Example

				
					document.getElementById('demo').innerHTML = 'Hello JavaScript';
				
			

JavaScript Can Change HTML Attribute Values

In this instance, JavaScript modifies the value of a <img> tag’s src (source) attribute:

The Light Bulb

-------Table Mukvu-------

JavaScript Can Change HTML Styles (CSS)

Modifying an HTML property is comparable to changing the style of an HTML element:

Example

				
					document.getElementById("demo").style.fontSize = "35px";
				
			

JavaScript Can Hide HTML Elements

Changing the display style is one way to hide HTML elements:

Example

				
					document.getElementById("demo").style.display = "none";
				
			

JavaScript Can Show HTML Elements

Changing the display style is another way to make hidden HTML components visible:

Example

				
					document.getElementById("demo").style.display = "block";
				
			
Share this Doc

JS Introduction

Or copy link

Explore Topic