JavaScript Introduction | w3school
ThispagecontainssomeexamplesofwhatJavaScriptcando.JavaScriptCanChangeHTMLContentOneofmanyJavaScriptHTMLmethodsisgetElementById().Theexamplebelow"finds"anHTMLelement(withid="demo"),andchangestheelementcontent(innerHTML)to"HelloJavaScript":Exampledocument.getElementById("demo").innerHTML="HelloJavaScript";TryitYourself»[1]JavaScriptacceptsbothdoubleandsinglequotes:Exampledocument.getElementById(demo).innerHTML=HelloJavaScript;TryitYourself»[2]JavaScriptCanChangeHTMLAttributeValuesInthisexample...
This page contains some examples of what JavaScript can do.
JavaScript Can Change HTML ContentOne of many JavaScript HTML methods is getElementById().
The example below "finds" an HTML element (with id="demo"), and changes the element content (innerHTML) to "Hello JavaScript":
Exampledocument.getElementById("demo").innerHTML = "Hello JavaScript";
Try it Yourself »[1]JavaScript accepts both double and single quotes:
Exampledocument.getElementById(demo).innerHTML = Hello JavaScript;
Try it Yourself »[2] JavaScript Can Change HTML Attribute ValuesIn this example JavaScript changes the value of the src (source) attribute of an <img> tag:
JavaScript Can Change HTML Styles (CSS)Changing the style of an HTML element, is a variant of changing an HTML attribute:
JavaScript Can Hide HTML ElementsHiding HTML elements can be done by changing the display style:
JavaScript Can Show HTML El...