I have a div
that contains a register wizard, and I need hide/show this div
when a button is clicked.
How can I do this?
Below I show you the code.
Thanks :)
<div id="wizard" class="swMain">
<ul>
<li><a href="#step-1">
<label class="stepNumber">1</label>
</a></li>
<li><a href="#step-2">
<label class="stepNumber">2</label>
</a></li>
<li><a href="#step-3">
<label class="stepNumber">3</label>
</a></li>
<li><a href="#step-4">
<label class="stepNumber">4</label>
</a></li>
</ul>
<div id="step-1">
<h2 class="StepTitle">Perfil</h2>
<table cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="center" colspan="3"> </td>
</tr>
<tr>
<td align="right">Username :</td>
<td align="left">
<input type="text" id="username" name="username" value="" class="txtBox">
</td>
<td align="left"><span id="msg_username"></span> </td>
</tr>
<tr>
<td align="right">Password :</td>
<td align="left">
<input type="password" id="password" name="password" value="" class="txtBox">
</td>
<td align="left"><span id="msg_password"></span> </td>
</tr>
</table>
</div>
Use JQuery. You need to set-up a click event on your button which will toggle the visibility of your wizard div.
Refer to the JQuery website for more information.
This can also be done without JQuery. Using only standard JavaScript:
Then add
onclick="toggle_visibility('id_of_element_to_toggle');"
to the button that is used to show and hide the div.The following solution is:
getElementById
is called once at the outset. This may or may not suit your purposes.You can do this entirely with html and css and i have.
HTML First you give the div you wish to hide an
ID
to target like#view_element
and a class to target like#hide_element
. You can if you wish make both of these classes but i don't know if you can make them both IDs. Then have your Show button target your show id and your Hide button target your hide class. That is it for the html the hiding and showing is done in the CSS.CSS The css to show and hide this should look something like this
This should allow you to hide and show elements at will. This should work nicely on spans and divs.
Task can be made simple javascript without jQuery etc.
This function is simple if statement that looks if wizard has class swMain and change class to swHide and else if it's not swMain then change to swMain. This code doesn't support multiple class attributes but in this case it is just enough.
Now you have to make css class named swHide that has display: none
Then add on to the button onclick="showhide()"
So easy it is.
This can't be done with just HTML/CSS. You need to use javascript here. In jQuery it would be: