To link javascript to HTML we have to use the Html tag. There are two ways to link javascript to Html
javascript code inside in for example:
Linking external javascript files using src attribute of the <script> tag, linking javascript is called external javascript.
HTML Script Tag:
the html script tag is link the client-side javascript to HTML.
note:-, it’s a pair of opening(<script>) and closing (</script>) tags.
Embed (inline) JavaScript Example:
To embed javascript in Html we have to wrap our javascript code in between the opening() tag.
output:-
Where to Place the Script Tag (embedded javascript):
- head section
- body section
head section:-To load the javascript before loading the Html document itself, we reference the javascript code inside the of the Html document.
for example:
Link External JavaScript files:-
to link exernal javascript to write the scripting logic inside to seprate file(.js extension)
the types of Attribute:
The type attribute is an attribute of <script> tag.
syntax:-
In CSS we use attribute selectors to target specific HTML elements,
the shown in for example: