www.webdeveloper.com
Results 1 to 9 of 9

Thread: what is the rule re. script tags?

  1. #1
    Join Date
    Dec 2010
    Posts
    4

    what is the rule re. script tags?

    I'm learning javascript, and i see sample code for event handling (i.e. onmouseover), where the code is in the <body> section of the html, and there is no script tag and the example appears to work fine.

    Can somebody tell me the rules on when you need the script tag and when you don't?

    THanks!,
    Jeff S

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Question

    Quote Originally Posted by jefals View Post
    I'm learning javascript, and i see sample code for event handling (i.e. onmouseover), where the code is in the <body> section of the html, and there is no script tag and the example appears to work fine.

    Can somebody tell me the rules on when you need the script tag and when you don't?

    THanks!,
    Jeff S
    Show an example of what you are wanting to know about.

  3. #3
    Join Date
    Dec 2010
    Posts
    4

    ok, here's an example

    Why does the code below work without needing <script> </script>?
    I don't understand when you do need those script tags, and when you don't.


    <html>
    <head><title>"My page"</title>
    </head>
    <body>
    <a href="http://www.webdevelopersnotes.com/"
    onmouseover="alert('Go back to Home Page');
    document.bgColor='red'">Home Page</a>
    </body>
    </html>

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380
    The event 'onmouseover' is an HTML attribute.
    The 'document.bgColor' is a CSS assignment.
    No need for JS at this point.

    See: http://reference.sitepoint.com/html/...es/onmouseover
    or google "HTML onmouseover" for additional information.

  5. #5
    Join Date
    Dec 2010
    Posts
    4

    thanks, but...?

    Why is it, then, that I went thru my several online html tutorials and Murach's HTML/XHTMS CSS book, and never learned about "onmouseover"? Then, in every online javascript class or my Javascript book, that I'm learning about "onmouseover". Up to now, I thought it was a javascript event handler...Now I'm learning it's really html ...

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380
    Heck if I know!

    Why is it that ajax is not mentioned in every javascript book? It is JS, but only seen in advanced JS books!

  7. #7
    Join Date
    Dec 2010
    Posts
    4

    Thanks JM

    I think I've got it...or, at least it's ruminating in my brain, and it's starting to make sense...
    I've been told thru another forum that although the "onmouseover" is an html attribute, the value is a javascript command. So, it wouldn't be in a beginner's html book, since he wouldn't yet understand javascript.
    ( I think this stuff may be a little more complicated then the cobol I've been writing for the last 40 years!)

  8. #8
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380
    Well as I have converted from PL-1, Fortran, several assemblers, Forth, Basic, Pascal and others, I know you can transition to JS.
    Good Luck!

  9. #9
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    there is good reason you haven't seen onmouseover or onanything. That is what's called obtrusive javascript and violates the principle of separation of content, behavior, and presentation. All javascript should be in a javascript file or embedded in <script> tags, and all styling should be in a css file or embedded in <style> tags. Neither should be an attribute of an element.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles