Click here to Skip to main content
14,661,984 members
Rate this:
Please Sign up or sign in to vote.
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 :
<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 :
$(document).ready(function () {

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

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

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

       return false;
   });

});
Posted

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
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..
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100