Search code examples
jqueryasp.nettoggleclass

toggleClass() does not work for me?


I have a shopping bag in my page and i want pin and unpin this bag with toggleClass() jquery. To do this, i use a "fix" class, but my solution does not work. when i click on input button, "fix" class is added to li element but when i click on input button again, "fix" class will not be removed. Please help me. Thank you.

my .aspx:

<ul class="menu">
<li>...</li>
<li>...</li>
<li>...</li>    
<li class="dropdown right transition">
    <a href="#" class="dropdown-toggle">

    </a>
    <asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate>
        <div class="grid-container5">
            <div class="dropdown-inner form">
                //my Shopping bag
            </div>
            <input id="pin" type="submit" name="pin" value="" class="pin" />
        </div>
    </ContentTemplate></asp:UpdatePanel>
</li>
</ul>

my jquery:

$(function () {
   $("#pin").click(function () {
      $(".menu li.dropdown").toggleClass("fix");
   });
});

Solution

  • thats because you are using input type=submit..make it button it ll work... every time you click on submit button it submits the page back to CS page And posts back.And when it posts back The aspx page cannot rebind the jquery events with it .so you do not see its working after the postback. if you make the input type button it will not postback and do its work as it is supposed to do.