SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is it javascript or is it html ?

    I'm brand new to html and javascript. In the online html tutorials i've gone thru, and my html book (Murach's HTML, XHTML & CSS), there has been no mention of "onmouseover" --it's not even in the index. It's only once I started studying javascript that I run into "onmouseover". Now I learn that "onmouseover" is actually an html attribute, and on sitepoint's discussion regarding html attributes, it says "onmouseover has been around as long as javascript".

    So, I'm confused; is it html or is it javascript? And, if it's html, why say that it's been around as long as javascript? And why isn't it mentioned in books designed to teach html as opposed to books designed to teach javascript?

    Thanks,
    Jeff S

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    OnMouseOver is a HTML attribute, but the value is written in javascript. It's an event attribute - the script inside it is fired when such an event occurs, and onclick is another example of this kind of attribute.

    For example:
    Code html:
    <button onclick="alert('This is a JavaScript command, fired by HTML')">Click Me</button>

    HTML and JavaScript are deeply connected, so things like this do crop up.

    Without a knowledge of HTML, one can't really do well with JavaScript. Without a knowledge of JavaScript, one wouldn't have a clue what to do with onmouseover. Therefore it's neglected from beginner HTML books.

    It's actually classed as bad practise to have inline onmouseover events nowadays. If they're defined in a script file, it saves one repeating code.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,596
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Hi jefals, welcome to SitePoint!

    I think of it as a kind of hook in the html that javascript can then do things with. On its own it does nothing. So to say that it's been around as long as JavaScript is to say that it's been around since the beginning of JavaScript--that is, it was a part of JS right from its inception.

    So it's only relevant in the context of JavaScript, so will only appear in a JavasScript book.

    Here is some more info from the SP reference:
    http://reference.sitepoint.com/html/...es/onmouseover

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Ralph and Jake. It's starting to make sense to me, thanks to your explanations. I'm a legacy app. programmer -- been programming for 40 years, but now I need to learn Sharepoint -- and, I find, in order to learn Sharepoint, I've got a LOT of prerequisites before I even get to that point -- with HTML/CSS/Javascript being just the beginning....I feel like a guy 40 pounds overweight who suddenly finds himself tasked with having to climb Mt. Everest!

    I appreciate the help!

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,600
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Basically it was introduced into HTML as a way to attach JavaScript when JavaScript was first introduced. Once it became possible to attach JavaScript to web pages in an unobtrusive manner the HTML attributes that used to be required to attach it became redundant and are now better avoided.

    Instead of:

    <div onmouseover='x()'>

    you can use

    <div id='xx'>

    and in the JavaScript use

    document.getElementById('xx') = x;

    to achieve the same thing without jumbling your JavaScript and HTML together (since the values those HTML attributes have IS JavaScript regardless of what you consider the attributes to be).

    Also they are not HTML attributes in quite the same way as other HTML attributes since from within JavaScript you can't treat them as HTML attributes.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, I agree, re. keeping it in a separate script file. But I know I will see these types of statements in the htmls, so I am thankful to these forums where I can ask the pros, and get some understanding. I guess the best way to learn is in a classroom where, when you have questions, there's an instructor right there to answer -- but this is a pretty good substitute!.


Bookmarks

Posting Permissions

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