Aaron Thomas Aaron Thomas - 2 years ago 74
Javascript Question

.toggle() sometimes taking double click before working

I have a simple application, where I'd like to toggle between showing and hiding elements in a fieldset using jQuery's .toggle effect. The trouble is, occasionally I have to double-click the button that enables the toggle, to get it to work.

Any ideas on what's going on?


<!DOCTYPE html>
<script src="jquery-2.1.1.min.js"></script>
<script src="test.js"></script>
<div class="LeftFrame">
<div id="LeftTable"><strong>Left</div>
<div id="MainTable"><strong>Main
<form><fieldset><legend><button id="buttonShowFields">Add Info</button></legend>
<div id="InfoAddFields">
ID: <input type="text"><br>
Serial Number: <input type="text"><br>
Location: <select id="inputLocation">
Status: <select id="inputStatus">
<option>In Process</option></select><br>

... and javascript (test.js ref in html above):

// Show options to add workorder
// $("#WOAddFields").hide();


Answer Source

Prevent the submit with event.preventDefault() when you click the button



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download