Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to change color of the list on clicking anchor tag using jquery. On clicking the anchor tag i have called a C# function code behind.. if i give return false code in jquery like the below code the color has changed. but code behind function is not working. once i comment return false from jquery the code behind code is working but the color has not changed.

html code :
ASP.NET
<ul class="ullist" id="navlist">

    <li id="list1"><a id="a1"  runat="server" >Active</a></li>

 <li id="list2"><a id="a2"  runat="server" >Abeyance</a></li>

</ul>


Jquery Code :
JavaScript
$(document).ready(function () {

    $("a").click(function () {

       $("li.active1").removeClass("active1");

                   $(this).parent('li').addClass('active1');

       return false;
   });

});
Posted

Did you use update panel inside your page? If so, then you need to re initialize the jquery ready function so that this event can be fired when page is being postback.
You can find a tip for this kind of issue here.
 
Share this answer
 
v2
Comments
januskarthik 14-Nov-14 0:26am    
thank you for reply. but its not work for me. i do not know how to use ajax please help me with my example code..
Pradip R 14-Nov-14 1:01am    
Do you have UpdatePanel in your page?
januskarthik 14-Nov-14 2:31am    
i have partially completed. i want to use jquery variable inside the id field in jquery like below.

var value="list1";
$('#list1').addclass('active); // this working fine.
but i want to use variable value instead of #list1 like
$(value).addclass('active'); // this not working

how can do that..
As per your comment, you need to prepend '#' for ID and '.' for class. You can achieve that by following:
JavaScript
var value="list1";
$('#' + value).addclass('active'); // this is the right way when you have dynamic ID.
 
Share this answer
 
v2

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