Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a div tag with an anchor tag within that. When I click on the div tag, I want the background colour and font colour to change. Although I have read a few posts on this, Iam unable to get a working solution.

Appreciate any help. Thank you all.

XML
<div class="select" style="top: 224px"><a href="ATSSearch.aspx">Search Applications</a></div>
Posted

1 solution

XML
<head runat="server">
    <title></title>
    <script language="javascript">
        function ChangeDiv(div) {
            div.style.backgroundColor = '#cccccc';
            document.getElementById("lnkSearch").style.color = "#000000";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div onclick="ChangeDiv(this)" class="select" style="top: 224px"><a href="#" id="lnkSearch">Search Applications</a></div>
    </form>
</body>
 
Share this answer
 
Comments
sunainanz 27-Sep-10 21:01pm    
Thanks for the answer. The div changes backgound colour until the muose is clicked and when the postback takes place, it goes back to original colour defined in class='select'. any thoughts ?? :(
sunainanz 27-Sep-10 21:13pm    
but, if I click outside of the a link but within the div, it works. I use the link only to navigate.
Al-Farooque Shubho 27-Sep-10 23:04pm    
If turns out that you want the div background color and font color to be changed only if user clicks the hyperlink. In that case, you should change the hyperlink color using the css style property a:visited (You can Google how to do this), and, you should change the div background color in the CodeBehind (By setting a Div "ID" and runat="server" attribute)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900