Attributes for script tag

For a basic thing, HTML element can contain some attributes. For example you can set background color in the ‘<body>’ tag by following code:

Code

<body bgcolor=’blue’>

</body>

‘<Script>’ tag can also have some attributes to set its properties. The first one is for choosing a language. Scripting has different languages such as JavaScript, VBScript, LiveScript and etc. we must define in which language we will write our codes. If you don’t write anything here, it choose JavaScript as the language for default. Look at the following example to see the usage of this attribute:

Code

<script language =”javascript”>

</script>

The code we are writing inside the script tag in the same page called internal javascript.

The another attribute for script tag is is ‘src’. It is useful for when you have a collection of JavaScript codes and you want to save it outside of current page because of some reasons (maybe you want to use them in different pages , they get a lot of space in the current page or script is in another domain). In this case, just copy your codes in a new notepad file and save it with ‘.js’ extention. then call it in ‘src’ part. For example if this file is put in the ‘js’ directory with ‘first_js.js’ as its name you can call it in this way:

Code

<script src =”js/first_js.js”>

</script>

The code we are writing in an another file and referring that file into the page is called external javascript.

Leave a Reply

%d bloggers like this: