How to use JavaScript to change the text in the link color and font!!

Source: Internet
Author: User

Today, the manager said the customer will be the first page of the link font style change, is to move the mouse to a link (is <a></a>) above the time, the link font and color to become bold and red, and the mouse moved away, the color is still unchanged, I just started with style: a.link:hover {color: #FF0000; Font-weight:bold}, but if you want to do this, just move the mouse will change, remove or will become the previous style, the customer's demand is: Move up after the change, move away after still keep the link for Bold and red. In the end, I solved it myself in this way:

First, get the text in the link, such as my link for <a id= "Aarr" >ARRIVAL</A>, get the text in the link to the JS code:

var val = document.getElementById ("Aarr"). innertext;

Then I'm going to change the color of the text to red, and the code is as follows:

val = Val.fontcolor ("Red");

Finally, I insert this text into its link:

document.getElementById ("Aarr"). InnerHTML = val;

Note: You cannot write document.getElementById ("Aarr"). innertext = Val; otherwise, the color of the font will not change.

If you want to change the font to bold, you can do this: document.getElementById ("Aarr"). Style.fontweight = "bold";

To do this, I just call the above JavaScript code in the onmouseover event of this link.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.