14

Me and my programmer has 2 different views for what "Inline JavaScript" is.

  1. I said inline JavaScript means JavaScript placed directly in the HTML file, without in a .JS file.

  2. My programmer means inline JavaScript is JavaScript on 1 line, and like <button onclick="alert('test')">

I give him right in, that inline JavaScript also is "onclick='alert(...)" because it again is like my solution #1, all JavaScript loaded in HTML and not in JS.

Who's right?

We have a HTML file, and there is <script>....</script> JavaScript in the bottom, that is inline javascript, right?

3
  • 5
    Does it matter? Agree on a common vocabulary for your conversation and move on. Commented Oct 27, 2013 at 13:30
  • 1
    Old question but it needs to be updated. It DOES matter and the definition of "inline" is not up for debate: Content-Security-Policy: "A policy needs to include a default-src or script-src directive to prevent inline scripts from running" Commented Oct 7, 2018 at 3:42
  • @Sosukodo if that's an important bit, the question should be reworded carefully or a new one should be created. As currently written, the question doesn't make much sense at SO Commented Jul 27, 2019 at 11:18

2 Answers 2

21

A script tag without a src (ie. with code directly in the HTML document) is referred to as an inline script.

An onclick="..." attribute is called an inline event handler.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for "inline event handler" -- I knew there was a term I was forgetting!
Great info, but you have not answered his question of who is right, or are neither right. I guess your answer may be suggesting that they are both wrong?
@barlop Woo, old answer :D But yes, my position is that they are both wrong... mostly. An inline script may be ok if it's doing something like setting up configuration for an external script, or maybe a loading screen (since having to load the loading screen would be... weird).
4

I've heard the term used for both of those, I don't think either of you is "wrong." I'd say I've heard it used more for #1 than for #2. Most terms I've heard for #2 are more clunky, like "onxyz event handler" or "inline event handler" (thank you Niet the Dark Absol for reminding me) or "DOM0 attribute event handler" or sometimes just "DOM0 handler."

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.