473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

onMouseOver & arrays - using style to modify border

The code below is meant to go through all images on the page, and add a
red border on the mouseover, and a white border on the mouseout. It's
not working and I've spend too many hours on this - please help!

Thanks... code below....

<img src="someImage.jpg">

<script type="text/javascript">
var img_elems = document.getElementsByTagName("img");

for (var i=0;i<img_elems.length;++i)
{
var img_src = img_elems[i].src;
img_elems[i].onmouseover="this.style.borderColor='red'";
img_elems[i].onmouseout="this.style.borderColor='white'";

}
</script>

Aug 22 '06 #1
2 4798

bu******@gmail.com wrote:
The code below is meant to go through all images on the page, and add a
red border on the mouseover, and a white border on the mouseout. It's
not working and I've spend too many hours on this - please help!

Thanks... code below....

<img src="someImage.jpg">

<script type="text/javascript">
var img_elems = document.getElementsByTagName("img");

for (var i=0;i<img_elems.length;++i)
{
var img_src = img_elems[i].src;
img_elems[i].onmouseover="this.style.borderColor='red'";
img_elems[i].onmouseout="this.style.borderColor='white'";

}
</script>
Try the following:

<script type = "text/javascript">
function setup()
{
var len = document.images.length;

for(var i = 0; i < len; ++i)
{
assignEvent(i);
}

}

function assignEvent(index)
{
document.images[index].onmouseout = mOut;
document.images[index].onmouseover = mOver;
}

function mOut()
{
this.style.border = "1px solid white";
}

function mOver()
{
this.style.border = "1px solid red";
}

window.onload = setup;
</script>

For border color to work, you'll need border width. That's the reason
for using border instead of assigning all of those separate css values.

Aug 22 '06 #2
THanks it works!
web.dev wrote:
bu******@gmail.com wrote:
The code below is meant to go through all images on the page, and add a
red border on the mouseover, and a white border on the mouseout. It's
not working and I've spend too many hours on this - please help!

Thanks... code below....

<img src="someImage.jpg">

<script type="text/javascript">
var img_elems = document.getElementsByTagName("img");

for (var i=0;i<img_elems.length;++i)
{
var img_src = img_elems[i].src;
img_elems[i].onmouseover="this.style.borderColor='red'";
img_elems[i].onmouseout="this.style.borderColor='white'";

}
</script>

Try the following:

<script type = "text/javascript">
function setup()
{
var len = document.images.length;

for(var i = 0; i < len; ++i)
{
assignEvent(i);
}

}

function assignEvent(index)
{
document.images[index].onmouseout = mOut;
document.images[index].onmouseover = mOver;
}

function mOut()
{
this.style.border = "1px solid white";
}

function mOver()
{
this.style.border = "1px solid red";
}

window.onload = setup;
</script>

For border color to work, you'll need border width. That's the reason
for using border instead of assigning all of those separate css values.
Aug 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Utada P.W. SIU | last post by:
Dear All, I would like to using style sheet in ASP generated Excel, but it sees cannot using it. Here's my code: '------------------- CODE ----------------------------------------- <style>...
2
by: J. Campbell | last post by:
I have a class that contains an array of integers that hold the state of my 'system'. The system must be updated periodically. I need to update the whole system at once, at which point the system...
2
by: MV | last post by:
How do I check if a browser supports an image using style before writing it with document.write? document.write("<img id='picture1' src='a.gif' alt='blah' style='blah'>"); NN4 and Opera 6 throw...
0
by: The Coolest Dolphin | last post by:
OnMouseOver & OnMouseOut event on tablerow to change backcolor of row Hi everyone, I'm looking for a way to use a mouseover/mouseout event (normally done via javascript) via Visual...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
1
by: ravichobey | last post by:
Hi all, I am currently writing a C based CGI scripting.When i am not using any style sheets in my program,it compiles and executes properly. But when i am using style sheets,it is giving...
7
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
1
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.