Change Background Color
Undo Background Color
HOME
ABOUT WEB PAGE
ABOUT JAVASCRIPT
ABOUT HTML
ABOUT US


TIPS AND TRICKS FOR CODING




 

Java Script Introduction


< !DOCTYPE html > < html > < body > < p > JavaScript can write directly into the HTML output stream: < / p > < script > document . write ( " < h 1 > This is a heading < / h 1 > " ) ; document . write ( " < p > This is a paragraph. < / p > " ) ; < / script > < p > You can only use document.write in the HTML output. If you use it after the document has loaded (e.g. in a function), the whole document will be overwritten. < / p >

< / body > < / html >
TRY IT

JavaScript: Reacting to Events


< !DOCTYPE html > < html > < body > < h 1 > My First JavaScript < / h 1 > < p > JavaScript can react to events. Like the click of a button: < / p > < button type = " button " onclick = " alert ( ' Welcome !' ) " > Click Me! < / button > < / body >
TRY IT


JavaScript: Changing HTML Content


< !DOCTYPE html > < html > < body > < h1 > My First JavaScript < / h1 > < p id = " demo " > JavaScript can change the content of an HTML element. < / p > < script > function myFunction ( ) { x = document . getElementById ( " demo " ) ; // Find the element x . innerHTML =" Hello JavaScript! " ; // Change the content } < / script > < button type = " button " onclick = " myFunction ( ) " > Click Me! < / button > < / body > < / html >
TRY IT

JavaScript: Changing HTML Images


< ! DOCTYPE html > < html > < body > < script > function changeImage ( ) { element=document.getElementById ( ' myimage ' ) if ( element .src . match ( " bulbon " ) ) { element . src = " pic _ bulboff . gif " ; } else { element . src = " pic_bulbon.gif " ; } } < / script > < img id = " myimage " onclick = " changeImage ( ) " src = " pic_bulboff .gif " width = " 100 " height = " 180 " > < p > Click the light bulb to turn on/off the light< / p > < / body > < /html >
TRY IT

JavaScript: Changing HTML Styles


< !DOCTYPE html > < html > < body > < h1 >My First JavaScript < /h1 > < p id = " demo " > JavaScript can change the style of an HTML element. < / p > < script > function myFunction () { x = document . getElementById ( " demo " ) // Find the element x . style . color = " #ff0000 " ; // Change the style } < / script > < button type="button" onclick="myFunction () " > Click Me ! < / button > < / body > < /html >
TRY IT

JavaScript: Validate Input


< !DOCTYPE html > < html > < body > < h1 > My First JavaScript < /h1 > < p > Please input a number. < /p > < input id = " demo " type = " text " > < script > function myFunction ( ) { var x = document . getElementById ( " demo " ) . value ; if ( x = = " " || isNaN ( x ) ) { alert ( " Not Numeric " ); } } < / script > < button type = " button " onclick = " myFunction ( ) " > Click Me! < / button > < / body > < / html >

TRY IT

Did You Know?


JavaScript and Java are two completely different languages, in both concept and design. Java (invented by Sun) is a more complex programming language in the same category as C. ECMA-262 is the official name of the JavaScript standard. JavaScript was invented by Brendan Eich. It appeared in Netscape (a no longer existing browser) in 1995, and has been adopted by ECMA (a standard association) since 1997.


MUSIC STUDIO