Mr Geek Mr Geek - 4 months ago 11
Javascript Question

Is there a script attribute in HTML5

Is there a script attribute in HTML for JS, like the style attribute for CSS, I asked this because I'm using an IDE that highlights script attributes inside elements, so I thought it might exist, and if it does, how to use it ?


<element style="it exists, and i know how to use it" script="no clue">...</element>

Answer

HTML5, like previous HTML elements, does not have script attribute but has a script element: https://www.w3.org/TR/html5/scripting-1.html#the-script-element. You can either put some script directly between two <script> and </script> tags, or use the script element to refer to an external JavaScript file. The JavaScript itself can than dynamically (e.g. on load) add event listeners to HTML elements that need to respond to specific events.

Comments