0

I have included the javascript file I have at the top of the HTML file

<link rel="script" type="text/css" href="click.js">

And in my onClick attribute of h3, I have passed onInfoClick().

The onInfoClick function in JS:

function onInfoClick() {
    window.open('http://easydiet.io/panel-info.php', '_self');
} 

When I click the <h3>, I get an Uncaught Reference Error. I know that I probably can wrap the <h3> in an <a>, and add the href="" property, but is there any other way I can do this as <h3> doesn't support the href property?

Sean Goudarzi
  • 1,244
  • 1
  • 10
  • 23

4 Answers4

1

You have injected you script incorrect. Use next syntax:

<script src="click.js" type="text/javascript"></script>
VadimB
  • 5,533
  • 2
  • 34
  • 48
  • What would happen if I use the tag instead of – Sean Goudarzi Dec 26 '16 at 10:11
  • 1
    The link tag shows the browser there is a relationship between two documents; in this case, the link tags says that the page gets its javascript from some external file, so the browser should load it. The script tag just tells the browser that the source of the javascript is some file. So I think - `script` tag is fully optimized in browser to work with scripts only while link tag is more abstracted and can be used to link different documents so we may have differences as it is not tight hard to script behavior only but describes all avaliable references (styles, alternate urls, etc) – VadimB Dec 26 '16 at 10:31
0

Type should be text/javascript instead text/css

<link rel="script" type="text/javascript" href="click.js">

Update

<link type="text/javascript" src="click.js">
Curiousdev
  • 5,668
  • 3
  • 24
  • 38
0

Or try this way

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

It should work too.

Rahul
  • 18,271
  • 7
  • 41
  • 60
0

Per the documentation:

<!-- HTML4 et (x)HTML -->
<script type="text/javascript" src="javascript.js">

<!-- HTML5 -->
<script src="javascript.js"></script>
Patrick Ferreira
  • 1,983
  • 1
  • 15
  • 31