Javascript DOM provides the functionality to change the Link text color using onmouseover event dynamically. You can use the document. getElementById method in a javascript function to access the specified Hyperlink anchor <a> tag of HTML and change the color of text by calling the javascript function on its onmouseover event. Use the value of id attribute of anchor <a> link HTML tag to pass it to the getElementById method. Javascript document object provides the getElementById method that provides the style object having all the CSS style properties such as color, backgroundColor etc.
document. getElementById("id"). style. color = "value";
You can pass the value as color name or #RRGGBB hex code value for color to the above code for changing the style color of text. Above code allows you to get or set the font color of the HTML element whose id is passed to the getElementById method of document object.
You can use the onmouseover event to change the link text color and onmouseout event to change back the color of link text to its initial default color.
Javascript this object can also be used to access the CSS style properties through style object. Syntax example:
this. style. color = "value";
this object of javascript is used inline in the HTML tag code so that this object could get the reference to the HTML tag in which it is being used.
Be the first to rate this post
Tags: javascript, html, dom, javascript change link color, html anchor tag, hyperlink text color, javascript tutorials, html tutorials, javascript getelementbyid, javascript style object, dhtml, dynamic html, change link text color onmouseover
7/29/2008 9:02:27 AM
Thank you With this event its better to do because the css doesnt work all the time with different browsers.
Anders
10/11/2008 3:21:35 AM