Djaouad
Djaouad

Reputation: 22776

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>

Upvotes: 1

Views: 100

Answers (5)

Tsundoku
Tsundoku

Reputation: 2707

HTML5, like previous HTML elements, does not have a 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 <script> and </script> tags, or use the script element to refer to an external JavaScript file. The JavaScript itself can then dynamically (e.g. on load) add event listeners to HTML elements that need to respond to specific events.

Upvotes: 2

Amr Elgarhy
Amr Elgarhy

Reputation: 69002

No there is no standard attribute in HTML 5 called script. But as previous answers listed, your IDE may highlighted this because it highlight any attribute, or script keyword for something else based on your file type.
Also note that while script is not a standard attribute in HTML 5 but this doesn't mean you can't use it, you can write your own custom attributes to any element to access it using javascript getAttribute

Upvotes: 1

poppertech
poppertech

Reputation: 1294

As the other answers state, no script attribute exists. From w3.org,

There are two types of scripts authors may attach to an HTML document:

  • Those that are executed one time when the document is loaded by the user agent. Scripts that appear within a SCRIPT element are executed when the document is loaded. For user agents that cannot or will not handle scripts, authors may include alternate content via the NOSCRIPT element.

  • Those that are executed every time a specific event occurs. These scripts may be assigned to a number of elements via the intrinsic event attributes.

Upvotes: 1

Paul
Paul

Reputation: 36339

No, there is no 'script' attribute. The IDE is probably doing a match on the pattern, without regard to context.

Upvotes: 2

Brad
Brad

Reputation: 163438

Your IDE is simply highlighting any tag attribute. Try making up some gibberish, and you'll see that it's highlighted.

Upvotes: 1

Related Questions