0% found this document useful (0 votes)
95 views8 pages

HTML JavaScript

This document provides an overview of JavaScript and how it can be used to manipulate HTML content and styles. It discusses common JavaScript methods like getElementById and includes examples of changing HTML, styles, and attributes. It also covers the noscript tag for browsers that don't support scripts.

Uploaded by

Zi Xi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
95 views8 pages

HTML JavaScript

This document provides an overview of JavaScript and how it can be used to manipulate HTML content and styles. It discusses common JavaScript methods like getElementById and includes examples of changing HTML, styles, and attributes. It also covers the noscript tag for browsers that don't support scripts.

Uploaded by

Zi Xi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

w3schools.

com

Ad covered
Never
content
Lose a Ticket Again

HTML JavaScript
❮ Previous Next ❯

JavaScript makes HTML pages more dynamic and interactive.

Example

My First JavaScript
Click me to display Date and Time

Try it Yourself »

The HTML <script> Tag


The <script> tag is used to define a client-side script (JavaScript).

The <script> element either contains script statements, or it points to an external


script file through the src attribute.

Common uses for JavaScript are image manipulation, form validation, and dynamic
changes of content.

To select an HTML element, JavaScript most often uses the


document.getElementById() method.

This JavaScript example writes "Hello JavaScript!" into an HTML element with
id="demo":

Example

<script>
document.getElementById("demo").innerHTML = "Hello
JavaScript!";
</script>

Try it Yourself »

Tip: You can learn much more about JavaScript in our JavaScript Tutorial.

A Taste of JavaScript
Here are some examples of what JavaScript can do:

JavaScript can change HTML content

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

Try it Yourself »

JavaScript can change HTML styles

document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "red";
document.getElementById("demo").style.backgroundColor =
"yellow";
Try it Yourself »

JavaScript can change HTML attributes

document.getElementById("image").src = "picture.gif";

Try it Yourself »

API & Integration Guide


Best Practice Tutorial

Get Started With Comprehensive Tools &


Step-by-step Tutorial.
mulesoft.com

OPEN

The HTML <noscript> Tag


The <noscript> tag is used to provide an alternate content for users that have
disabled scripts in their browser or have a browser that doesn't support client-side
scripts:

Example

<script>
document.getElementById("demo").innerHTML = "Hello
JavaScript!";
</script>

<noscript>Sorry, your browser does not support JavaScript!


</noscript>
Try it Yourself »

HTML Script Tags


Tag Description

<script> Defines a client-side script

<noscript> Defines an alternate content for users that do not support client-side
scripts

HTML Exercises

Test Yourself With Exercises

Exercise:
Use JavaScript to change the HTML content of the <p> element to "Hello
World!".

<body>

<p id="demo">Hi.</p>

<script>
document. ("demo").innerHTML = "Hello
World!";
</script>

</body>

Submit Answer »
Start the Exercise

❮ Previous Next ❯

Ad covered
Never
content
Lose a Ticket Again

COLOR PICKER

HOW TO

Tabs
Dropdowns
. / MORE - Accordions
0
Side Navigation
Top Navigation
Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List

SHARE

* +
,
CERTIFICATES
HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML

Read More »

API & Integration Guide


Best Practice Tutorial

Get Started With Comprehensive Tools &


Step-by-step Tutorial.
mulesoft.com

OPEN

REPORT ERROR

PRINT PAGE

FORUM

ABOUT

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
Java Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
jQuery Reference
Angular Reference
Java Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples

Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate

Get Certified »
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading
and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our
terms of use, cookie and privacy policy. Copyright 1999-2019 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

You might also like