Click here to Skip to main content
15,887,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am trying to navigate to different pages on click on the

While doing that i want to change the color of the text as red. It looks simple but i googled many things not able to get the proper answer.
my code:
HTML
<div id="divMyInformation">
                <table cellpadding="0" cellspacing="0" class="vertNavMyInfo" id="tblMyInformation">
                    <tr class="lvl1" onmouseover="OnMouseHoverColor(this)"  önmouseout="OnMouseOutColor(this)">
                        <td class="imgLinks">
                            <div  önclick="location='../Home/MyPage.aspx'">My Page
                            </div>
                        </td>
                    </tr>
                    <tr class="lvl1" onmouseover="OnMouseHoverColor(this)"  önmouseout="OnMouseOutColor(this)">
                        <td class="imgLinks" >
                            <div  önclick="location='../Home/MyPage1.aspx'">
                                My Page1                                                                
                            </div>
                        </td>
                    </tr>
                    <tr class="lvl1" onmouseover="OnMouseHoverColor(this)"  önmouseout="OnMouseOutColor(this)">
                        <td class="imgLinks" >
                            <div  önclick="location='../Home/MyPage2.aspx'">
                                My Page2
                            </div>
                        </td>
                    </tr>                    
                </table>
            </div>
Posted
Updated 12-Nov-13 3:02am
v3
Comments
swapnil_jadhav 12-Nov-13 8:29am    
Can you please elaborate as in you need to change the text color of "My Page" or any other text
sasen903 12-Nov-13 8:34am    
yes I want to change the "My Page" text color but only when i clicked on to it.
mean
there is a navigation
my page
my page1
My page2
After click on my page it should navigate to my page and change the color of my page as red. Rest of the pages(my page1, my page2) should remain black.
♥…ЯҠ…♥ 12-Nov-13 8:39am    
Its browser functionality I believe, you want to intimate user that link is visited already kind of right?
sasen903 12-Nov-13 8:40am    
Yes
swapnil_jadhav 12-Nov-13 8:44am    
Ok you can create a class in your css file as
.MyPage
{
color:red;
}

and on click of the above div you can add the class to it

for example:

<div önclick="location='../Home/MyPage.aspx'" id="MyPage">My Page</div>

$(document).ready(function(){
$('#MyPage').click(function() {
$('#MyPage').addClass('MyPage')
});
});

If possible please give me your complete code so i can write it neatly or it is good if you understand from the above example i have given :)Happy Coding!

1 solution

Hi sasen,

Try this code
XML
<!DOCTYPE html>
<html>
<head>
<style>
.clicked {color:red;}
</style>
<script type="text/javascript">
$('#clickMe').click(function() {
 alert('Test');
 $('#clickMe').addClass("clicked");
});
</script>
</head>
<body>
<div id="clickMe"> Click me </div>
</body>
</html>

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
Comments
Morgan Estes 12-Nov-13 8:53am    
This example only works of you're using the jQuery library. Be sure to add it in, or go with a vanilla JS solution.

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