Jump to content

Does JS need HTML to run?

Recommended Posts

Did you try it? :)The W3C requires browsers to be VERY flexible and forgiving. They should try to render documents with no HTML or incorrect HTML as best they can. As long as you have <script> tags, code written between them should execute.

Link to post
Share on other sites

You can also execute JavaScript in the URL of any page. The code will run as if it's part of the current page.For example, type the following in your browser:

java script:alert('There are '+document.getElementsByTagName('div').length+' "div" elements on this page.');

(NOTE: Remove the space between "java" and "script". The forum adds it for security reasons)As long as the code is one statement (possibly with closures... long story), you can do that.You can also open your browser's console and type there. On IE, press F12. Same on FF, but if you have Firebug installed.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...