3

I often see html elements with an onchange attribute that specifies javascript as the language, e.g.:

onchange="javascript:updateModel()"

It still works if I remove javascript:

onchange="updateModel()"

Is it safe to remove it? Are there some browsers (maybe older versions) that need it?

Dexygen
  • 12,287
  • 13
  • 80
  • 147
whistling_marmot
  • 3,561
  • 3
  • 25
  • 39

1 Answers1

5

Nothing. It shouldn't be there. It ends up being a label on a statement, so it's valid, it's just pointless.

You use javascript:, the pseudo-protocol, in attributes where a URL is expected (such as href), not in attributes that are already designed to contain JavaScript code like onclick.

Is it safe to remove it?

Yes.

Are there some browsers (maybe older versions) that need it?

No. :-)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875