AboutAndrew Hoffman Expertise I can field just about any question within this topic ranging from JavaScript to CSS, the two ingredients of DHTML. I`m very interested in the W3C and its validation rules for HTML, XHTML, and CSS, and enjoy answering questions of this type as well. I detest sleep and respond at all hours of the day or night.
Experience Experience in the area I've been working with DHTML and CSS for 7 years now and build/maintain websites of my own that implement DHTML navigation.
What I'm doing now My contract with Microsoft has ended and I am working for myself once again. Please contact me for any front-end work at antibland@gmail.com
How do you make a mouseover in DHTML only work when passing over text rather than passing over the page ?
Thanks,
Harry
ANSWER: Harry,
There may be other ways to do this, but here's mine. I specify which elements I want to receive the mouseover effect (whatever it is), and bind the mouseover events to ONLY these elements. This may seem slightly annoying, but I find it faster than looping through ALL elements, and filtering on everything. Run the code below to see it in action:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type="text/javascript">
window.onload = function() {
// specify the elements to receive the effects
var els = new Array('p', 'li', 'dd');
// declare variables
var el, i, j;
var len = els.length;
// loop through the array of elements
for (i = 0; i < len; i++) {
// get the current batch of elements ('example: all <p> tags')
el = document.getElementsByTagName(els[i]);
for (j = 0; j < el.length; j++) {
el[j].onmouseover = function() {
// specify whichever onmouseover effect you desire
this.style.color = 'red';
}
el[j].onmouseout = function() {
// specify whichever onmouseout effect you desire
this.style.color = 'black';
}
}
}
}
</script>
</head>
<body>
<p>Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 1500, cuando un impresor (N. del T. persona que se dedica a la imprenta) desconocido usó una galería de textos y los mezcló de tal manera que </p>
<dl>
<dt>definition title</dt>
<dd>definition data 1</dd>
<dd>definition data 2</dd>
</dl>
<img src="http://wvbr.com/images/uploads/after_dark_moon_guitar.jpg" width="377" height="358" alt="" />
<p>Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias desde el año 1500, cuando un impresor (N. del T. persona que se dedica a la imprenta) desconocido usó una galería de textos y los mezcló de tal manera que logró hacer un libro de textos especimen. No sólo sobrevivió 500 años, sino que tambien ingresó como texto de relleno en documentos electrónicos, quedando esencialmente igual al original. Fue popularizado en los 60s con la creación de las hojas "Letraset", las cuales contenian pasajes de Lorem Ipsum, y más recientemente con software de autoedición, como por ejemplo Aldus PageMaker, el cual incluye versiones de Lorem Ipsum.</p>
<img src="http://wvbr.com/images/uploads/after_dark_moon_guitar.jpg" width="377" height="358" alt="" />
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
</body>
</html>
---------- FOLLOW-UP ----------
QUESTION: Hi Andrew, I plead for your patience as this is very important.
I tried to paste your code into my frontpage but the code itself always showed up on the normal view page.
Below is "all" the code on my page.
Could you please insert your code and then return to me only what I need to paste into the html view on frontpage.