Jump to content
xisto Community
shiv

Change Table Colors On Mouse Effects! create onMouseover/onMouseout color effects within tables

Recommended Posts

Notice from szupie:

 

stun ur visitors with changing table colors!

 

change table rows or table cells bgcolor when mouse moves over elements of the table.

(works on IE only).

 

 

paste the following code into the table element that you want to change.

 

for example, if you want to change the table row you paste the code into the <TR>.

if you want to change a table cell color you paste the code on the <TD>.

you may even add it to the <TABLE> tag to highlight the entire table!

 

Code:

 

onMouseover="this.bgColor='lightgrey'"

onMouseout="this.bgColor='#FFFFFF'"

 

 

give different colors as u want!

 

njoy!

 

shiv

Share this post


Link to post
Share on other sites

Interesting piece of code...though i don't think it relates to Javascript at all sorry. It is basically another attribute under the <tr> tag with a little twist in it. It would be good for creating links though, to give it a contrasting color when you hover over it. How many browsers does it cover? Or does it only work with IE and FireFox?

Share this post


Link to post
Share on other sites

Actually, it is javascript realted as the onevent triggers are all javascript. It may only be compatible with IE and Firefox because IE defined the background color of an object to be bgColor and to be a part of the element. I haven;t tried this out, but theoretically, to give these effects to anyobject, replace

this.bgColor = "foo";
where foo is either the color name (one of the sixteen html defined presets) or the hex color code preceeded by the # sign with the following
this.style.backgroundColor = "foo";
where foo is the same as above.

~Viz

Share this post


Link to post
Share on other sites

Nice one :o

 

But I have heard that this is only limited to Internet Explorer.

I dont think that it will work with other Browsers as Firefox, Netscape Navigator etc :P

 

Anyone ???

who know that it also works on Firefox ??

 

 

Regards:

Samya Khalid

Share this post


Link to post
Share on other sites

I don't think such a simple function may be restricted)

Share this post


Link to post
Share on other sites

But I have heard that this is only limited to Internet Explorer.

I dont think that it will work with other Browsers as Firefox, Netscape Navigator etc :o

 

Anyone ???

who know that it also works on Firefox ??

Regards:

Samya Khalid

 


It works on the lastest version of Opera, Firefox, and IE. The style property was implemented in all DOM compliant browsers (as in getElementById["id"].style....)

Share this post


Link to post
Share on other sites

The following does work in Firefox (ver to.0.0.7)onMouseover="this.style.backgroundColor='#ffffff'"onMouseout="this.style.backgroundColor='#ff0000'"Cheers & thanks for that!-Alioop

Share this post


Link to post
Share on other sites
Changing table cell colorsChange Table Colors On Mouse Effects!

Hello.  Thank-you for the instructions above.  I like this website and find it very informative.  I'm setting up Crossword Puzzle webpages http://forums.xisto.com/no_longer_exists/.; Can you tell me how I can cause a particular cell to change color on the "crossword puzzle" grid when someone clicks on the clue number from the "clues" table.  Then, when they click the next clue, the prior cell changes back to the original color (with the rest of the puzzle grid) and the new cell changes color and so forth and so on.  Any help would be greatly appreciated.

Thank-you.

Chris Treu

Share this post


Link to post
Share on other sites

Changing table cell colorsChange Table Colors On Mouse Effects!

Hello. Thank-you for the instructions above. I like this website and find it very informative. I'm setting up Crossword Puzzle webpages http://forums.xisto.com/no_longer_exists/. Can you tell me how I can cause a particular cell to change color on the "crossword puzzle" grid when someone clicks on the clue number from the "clues" table. Then, when they click the next clue, the prior cell changes back to the original color (with the rest of the puzzle grid) and the new cell changes color and so forth and so on. Any help would be greatly appreciated.

Thank-you.

Chris Treu


To do this you must use the Javascript events onfocus and onblur of every input html tag of your page, these events will control the change of the background color of the DOM's offsetParent property, in this case will be the TD tags of your crossword puzzle grid. Also, you will use the Javascript event onclick of the A html tag that will force the execution of the previous events.

So, when you click on any clue number hyperlink on your clues table it will execute the onclick handler which first will scroll to the anchor location and then the related input tag will get focused activating the code attached to the onfocus event controller, in this case its related cell's background color will change, then when the input tag lost the focus it will activate the code attached to its onblur event, in this case will restore its related cell's background color to the original background color.

First copy the following Javascript function to the header section of your page:
<script type="text/javascript">
function focusElement(formName, elemName) {
   var elem = document.forms[formName].elements[elemName];
   elem.focus( );
   elem.select( );
}
</script>



And then attach the following code to every input tag on your crossword puzzle grid:

<input onfocus="offsetParent.style.backgroundColor='#555999'" onblur="offsetParent.style.backgroundColor='#ccccff'" type="text" name="3A-G" size="1" maxlength="1">



You can visit the Live Example that i create to view it in action.

BTW, i test this code only with Firefox 3 and internet explorer 6.

Best regards,

Share this post


Link to post
Share on other sites
to change text color as i moveover on the rowChange Table Colors On Mouse Effects!My cell of the table contains 3 (text) links to diffrent files.As I move over on the cell,my background color of that particular cell is being changed. But I want the color of all the 3 text also to change along with the background change.I am successful in changing the cell background.But not able to change all the 3 text colors at the same time.Please help me out of this problem if u r willing.Emailid: ambilibmenon@yahoo.Co.In-question by ambili

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.