Forum Moderators: open
sfHover = function() {
var sfEls = document.getElementById("content").getElementsByTagName("input");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" hover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
sfHover = function() {
function attach(arr) {
for (var i=0; i<arr.length; i++) {
arr[i].onmouseover = function() {
this.className += " hover";
}
arr[i].onmouseout = function() {
this.className = this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
var elContent = document.getElementById('content');
var elInputs = elContent.getElementsByTagName('input');
var elTextareas = elContent.getElementsByTagName('textarea');
attach(elInputs);
attach(elTextareas);
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<style type="text/css">
.hover {
background-color: #c00;
}
</style>
<title>Untitled</title>
</head>
<body>
<div id="content">
<input><textarea></textarea>
</div>
<script type="text/javascript">
sfHover = function() {
function attach(arr) {
for (var i=0; i<arr.length; i++) {
arr[i].onmouseover = function() {
this.className += " hover";
}
arr[i].onmouseout = function() {
this.className = this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
var elContent = document.getElementById('content');
var elInputs = elContent.getElementsByTagName('input');
var elTextareas = elContent.getElementsByTagName('textarea');
attach(elInputs);
attach(elTextareas);
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
</body>
</html>