Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the code I’ve:

First alternative:

<script type="text/javascript">

    /* ... */

</script>

Second alternative:

<script language="Javascript">

    /* ... */

</script>

Third alternative: An example code in JQuery's API reference:

<script src="http://code.jquery.com/jquery-latest.js"></script>

Can anyone tell me what should I use out of these all?

1 Answer

0 votes
by (19.7k points)

You don’t have to use the ‘language’ attribute as it’s deprecated. And "text/javascript" is the default script type on HTML5 so you don’t have to mention type either. 

If you use pages in XHTML 1.0 or HTML 4.01, you can’t omit type.  

If you validate the below code, it’ll give an error: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<script src="http://example.com/test.js"></script>

</head>

<body/>

</html>

This is the error you’ll get:

Line 4, Column 41: required attribute "type" not specified

Interested in Java? Check out this Java Certification by Intellipaat.   

Related questions

0 votes
1 answer
asked May 7, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Oct 3, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer

Browse Categories

...