y.m y.m - 1 year ago 72
HTML Question

jQuery toggle doesn't work in my page

I want to toggle a div with jQuery toggle function.

Here is my code:

$(document).ready(function () {
$("#removeSongButton").click(function () {

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<asp:Button runat="server" ID="removeSongButton" Text="remove song" />

<div id="radioButton1">
<asp:RadioButtonList runat="server" ID="radioButton">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:RadioButtonList >

when i click the "removeSongButton" the div togעle up and immediately toggle down. i think maybe the page reload.

Answer Source

You are right, its the reload. If the onliest thing you want to do by button-click is to toggle then add an preventDefault like this. Or are there other events you want to trigger by the button-click?

$("#removeSongButton").click(function (e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download