programminghead Logo

JavaScript :

JavaScript often known as JS, is a high-level, interpreted programming language. Its very popular for its dynamic, weakly typed, prototype-based and multi-paradigm programming.
In HTML its very impotent Because using JavaScript we can Program HTML Elements and change any HTML Element without Refreshing the Current page.

JavaScript in HTML :

As we know that HTML is used to Create layout for our website/Web-page and CSS used to Design/Style that Web-page's Elements. Because HTML is a Markup Language we have to use Programming Languages like JavaScript to do Programming inside HTML Webpage.
We can Create JavaScript Program inside HTML Document and we also include External JavaScript file inside HTML Document.

JavaScript inside HTML Document :

There is ways to Use or Include JavaScript Program inside HTML Document.

1. Internal JavaScript.
2. External JavaScript.

1. Internal JavaScript :

Using JavaScript Internally is very easy and commonly used way to do programming inside HTML Document. For internal JavaScript we have script <script< Tag for that.

Script Tag <script> :

Script Tag used to define JavaScript inside HTML document. we can use this <script> Tag inside <head> Tag and also <body> body tag.
if you want to run your JavaScript before your HTML Element's data then you have to define javaScript inside <head> tag. Because when our browser starts loading our HTML Document's data then the data inside the <head> tag will going to load first.
If you want to load your JavaScript after the HTML Documents the you can define JavaScript inside <body> Tag after the HTML Elements.

JavaScript Syntax inside HTML


<html>
 <head>
  <title>JavScript inside HTML</title>
 </head>
 <body>

   <script type="text/javascript">
     alert("hello worls");
   </script>

 </body>
</html>

Results


Script Tag <script> :

Script tag is used to define JavaScript inside HTML Document.

type attribute type="" :

Type attribute defines the language of the script or format of the data inside Script tag.

alert() method:

The alert() method displays an alert box with a specified message that we wrote inside the alerts double quotes.

2. External JavaScript :

Using External JavaScript file in HTML Document is a great way to manage your Codes. For including External JavaScript file first we have to write a JavScript code and Save that code file with the dot JS extension (javaFile.js).
And in HTML document we have to use Script <script> and inside the src="" attribute of script tag we have to give our source file/javaScript file's path.

External JavaScript Syntax


<html>
 <head>
  <title>JavScript inside HTML</title>

   <script type="text/javascript" src="myjavascript.js">
   </script>

 </head>
 <body>

 </body>
</html>

myjavascript.js file


 alert("hello worls");

Script Tag <script> :

Script tag is used to define JavaScript inside HTML Document.

type attribute type="" :

Type attribute defines the language of the script or format of the data inside Script tag.

src attribute type="" :

src attribute defines the Path for External JavaScript file.

alert() method:

The alert() method displays an alert box with a specified message that we wrote inside the alerts double quotes.

note:

Here we have 2 file. one file with .html extension and other one with .js Extension. if both the .html and .js file is on the same same folder, we only have to give file name with file extension (myjavascript.js) but if our javaScript file/.js file is in another folder/directory then we have to give full path of that .js file with file name and with file extension (C:/Desktop/HTML/myjavascript.js)

writing your name using JavaScript :

There are several ways to print/output some texts using JavaScript.
so in this example we are going to use these 3 JavaScript Methods to Print some text in output.
1. document.write();
2. alert();
3. console.log();

document.write() JS method:

This method of JavaScript print the Given text on the output scree. Here document targets the body part of the Browser and write defines/takes the value to display on the Output Screen.

document.write method's Syntax



 <html>
  <body>

   <script type="text/javascript">
     document.write("text");
   </script>

  <body>      
 <html>

alert() JS method:

This method displays the given text inside a alert Box. As a result you will see a small alert box over our browser displaying your given text and a ok button.

JS alert method's Syntax


 <html>
  <body>

   <script type="text/javascript">
     alert("text");
   </script>

  </body>
 </html>

JS console.log() Method :

This method of displaying text is little tricky. because you can't see your text in your browser body or in the alert box. to see your text you have to visit your browser's console menu. You can visit your Browser Console menu by pressing ctrl+shift+i keys combinations in Windows OS systems or you can right click inside your browser body and select inspect/inspect element option.

JS console.log() method's Syntax


 <html>
  <body>

   <script type="text/javascript">
     console.log("text");
   </script>

  </body>
 </html>

Printing Your name Using JavaScript


<html>
 <head>
  <title>My Name using JS</title>
 </head>
 <body>
  <script type="text/javascript">
   document.write("programminghead.com");
   alert("programminghead.com");
   console.log("programminghead.com");
  </script>
 </body>
</html>t;
 </html>

Results

Comments

free minecraft

http://tinyurl.com/y4rsu457
08:30 am

you are really a good webmaster. The web site loading velocity is amazing. It kind of feels that you are doing any unique trick. Furthermore, The contents are masterwork. you've done a excellent process in this topic!

g

http://tinyurl.com/y5skvzpz
07:24 am

constantly i used to read smaller content which also clear their motive, and that is also happening with this article which I am reading at this place.

g

http://t.co/HrbQRtcaU5
05:46 pm

Excellent, what a web site it is! This web site gives helpful information to us, keep it up.

g

http://tinyurl.com/y4rl4p4s
06:59 pm

hi!,I love your writing very much! percentage we keep in touch extra approximately your article on AOL? I need an expert on this area to unravel my problem. Maybe that's you! Taking a look ahead to look you.

g

http://t.co/GW5HaKlbx7
05:06 am

I delight in, result in I found exactly what I used to be looking for. You have ended my 4 day lengthy hunt! God Bless you man. Have a great day. Bye

download minecraft

http://tinyurl.com/y4awzz9m
04:17 am

Please let me know if you're looking for a article author for your blog. You have some really great posts and I feel I would be a good asset. If you ever want to take some of the load off, I'd love to write some material for your blog in exchange for a link back to mine. Please shoot me an email if interested. Cheers!

download minecraft for free

http://tinyurl.com/y2pshjqs
02:36 pm

Do you have a spam problem on this blog; I also am a blogger, and I was curious about your situation; we have created some nice methods and we are looking to swap methods with others, be sure to shoot me an email if interested.

minecraft download free pc

http://t.co/jnBGbHSIRT
11:20 am

I feel this is one of the most significant info for me. And i am happy reading your article. However wanna observation on few normal issues, The web site style is ideal, the articles is in reality great : D. Excellent job, cheers

gamefly

http://tinyurl.com/y5cxk8co
02:27 pm

Hi, just wanted to say, I enjoyed this post. It was inspiring. Keep on posting!

gamefly

http://tinyurl.com/y2v65t9v
04:50 pm

Awesome blog you have here but I was wanting to know if you knew of any discussion boards that cover the same topics talked about here? I'd really like to be a part of community where I can get feedback from other knowledgeable people that share the same interest. If you have any recommendations, please let me know. Thanks!

gamefly

http://tinyurl.com/y5sfglhb
01:58 pm

I blog quite often and I genuinely appreciate your information. This great article has really peaked my interest. I will book mark your blog and keep checking for new information about once a week. I opted in for your Feed too.

gamefly

http://t.co/5Rc47F3eqS
08:19 pm

If some one desires to be updated with most recent technologies afterward he must be visit this website and be up to date every day.

Write to Us