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

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:

<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.

Hi jefals, welcome to SitePoint! :slight_smile:

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:

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!:slight_smile:

I appreciate the help!

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.

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!.