user2728875 user2728875 - 3 months ago 6
jQuery Question

jQuery .click to toggle div content

I currently have the following div to display a certain result

<div id="results">
<span id="eresult">0</span>|
<span id="gresult">0</span>|
<span id="aresult">0</span>|
<span id="presult">0</span>|
<span id="vpresult">0</span>
</div>


However, I would like to toggle the visibility when I click on the following input button:

<input id="rbu" type="image" src="toggle.png" width="50" height="50">


This is my jQuery

$("#rbu").click(function () {
$("#results").toggle();
});


The div does disappear when clicked but it does not appear again. How do I make it show again?

Answer

This is working with Chrome, without any change in your code:

$("#rbu").click(function () {
    $("#results").toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="results">
  <span id="eresult">0</span>|
  <span id="gresult">0</span>|
  <span id="aresult">0</span>|
  <span id="presult">0</span>|
  <span id="vpresult">0</span>
</div>

<input id="rbu" type="image" src="toggle.png" width="50" height="50">

The error may be elsewhere in your code, try to clean it ?

Comments