Home » 2014 » February » 24 » A very simple example to learn Javascript in HTML

6:56 PM
A very simple example to learn Javascript in HTML

Here in this article, I will demonstrate use of javascript in html. How javascript can be used to help you build webpages.

 
Javascript is just like implementing functions or procedures on webpages. Suppose on click of a button, you want to do some action or you want to pop out a message, you can use java script.
 
  • Java script can be embeded in your html body tag directly
 
<html>
<title>
Title of webpage
</title>
<body>
<script>
 
<!--You can write any javascript code here-->
 
</script>
body goes here
</body>
</html>
 
  • Or you can put your Javascript in a seperate file named anything.js and give a link in your html file as below.
<html>
<head>
<title>
Title of webpage
</title>
<script src="anything.js" type="text/javascript"><script/>
</head>
<body>
body goes here
</body>
</html>
 
  • One simple example. Click the face to make it sad/happy..
Code Result
<html>
<body>
<script>
function makeMeHappy(){
elem=Documet.getElementById('hapy')
if(elem.src.match("sa")){
elem.src="/images/biggest-smiley2.jpg";}
else{
elem.src="/images/sad-smiley.png";
}
}
</script>
<img id="hapy"
src="/images/sad-smiley.png" alt="happy"  onclick="makehappy()">
</body>
</html>
Make me happy
 
 
 

Category: Technical Solution | Views: 2083 | Added by: shanky | Rating: 5.0/1

Related blogs


You may also like to see:


[2022-07-24][Technical Solution]
How to handle Criticism at work? An Insight by Mark Goulston (Harvard's Business review article)
[2015-12-30][Technical Solution]
SOLVED : Big problem of windows 10, internet speed reduces greatly. Turn off Windows update.
[2014-02-24][Technical Solution]
A very simple example to learn Javascript in HTML
[2015-02-04][Technical Solution]
Introduction to 3*3 Rubik's Cube basics
[2014-02-11][Technical Solution]
Advanced Encryption Standard (AES) algorithm : an algorithm for encryption and decryption for secure data transfer

Total comments: 1
avatar
1
1 Pooja Wadhwani • 12:43 PM, 2014-02-25
Awesome..
ComForm">
avatar