|Put your mouse over the following word:
You should have seen an alert box appear when your mouse went over the word. The code
is as follows:
<a href="#" onmouseover="alert('Mmm! Mices!
Yes, that's all! But look more closely. Did you notice that we start with double quotes
(") and put the text in the alert in single quotes (') ? And we
ended with a double quote.
Any text between a " (or a '
) and its matching quote (") must be on one line! So the text
'Mmm! Mices! Yum Yum'
Must be on one line and not split into two lines. Because of text wrapping, these lines
could appear broken. This will give an error. So:
onmouseover="alert('Mmm! Mices! Yum.
is wrapped by the browser and will give an error. The quotation (")
The onMouseOver event is enclosed in double quotes. If we used
double quotes for the text too, we would confuse java script so it would think the
onMouseOver event had ended when we started the text - after all, it had found its
matching quote! So we enclose the text in singles, and the event in doubles! The quotes
must match up!
Alternatively, we could have used single quotes for the onMouseOver event and double
for the text. We just have to keep the right quotes paired up!
We could use an onMouseOver event with a menu, loading a description page in a frame,
for example. Or we could use an image and have an onMouseOver for the hot spots! We'll
look at these a bit later.
Let's look at writing with java script next.