简体   繁体   中英

master page link's background colour is changing in Internet explorer but not working in Mozilla Firefox

I have one link whose background colour has to change when I click on it. So I have used a JavaScript function to do this,but it is working in Internet explorer but not changing in Mozilla Firefox.

The code is below:

function hilite() {
    Trend.style.background= "#000000";
}

Here trend is the id of the Link tag.

Link:

<a id="Trend" style="color: #FFFFFF;
 text-decoration: none;" href="ATrendAnalysis.aspx">Trend Analysis</a> &nbsp;&nbsp;

Cs file:

 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ScriptRegistration1", "hilite();", true);

In this case:

 Trend.style.background= "#000000";

"Trend" is a JavaScript variable, which is not defined. This is NOT referencing an element in the DOM.

Use:

document.getElementById('Trend').style.background= "#000000";

You could also try to apply some styles to the link using CSS by using the pseudo-class selector :active.

:Active would apply the defined style (in your case, it would be change its background color) only while the link is being pressed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM