Note that there are some explanatory texts on larger screens.

plurals
  1. POhide/show selected form with jQuery and css
    primarykey
    data
    text
    <p>i try to make an jQuery function for hide/show a form based on the user's choice!</p> <p>Here is my code that you will understand better.</p> <pre><code>… &lt;p id="joinChoice" class="parent"&gt; &lt;a href="" id="mastercardChoice" data-form-id="mastercardForm"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/a&gt; &lt;a href="" id="visaChoice" data-form-id="visaForm"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/a&gt; &lt;a href="" id="discoverChoice" data-form-id="discoverForm"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/a&gt; &lt;/p&gt; … &lt;div class="joinForm"&gt; &lt;div id="noneForm"&gt;&lt;/div&gt; &lt;div id="mastercardForm"&gt;&lt;/div&gt; &lt;div id="visaForm"&gt;&lt;/div&gt; &lt;div id="discoverForm"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>My CSS Code :</p> <pre><code>.joinForm { width: 55%; position: relative; height: 396px;} #noneForm { background: url("../img/ccard-none.jpg") no-repeat scroll 0 0 #FFF; height:396px; width:616px; position: absolute; top: 0; display: block; } #mastercardForm { background: url("../img/mastercard-form.jpg") no-repeat scroll 0 0 #FFF; height:396px; width:616px; position: absolute; top: 0; display: none; } #visaForm { background: url("../img/visa-form.jpg") no-repeat scroll 0 0 #FFF; height:396px; width:616px; position: absolute; top: 0; display: none; } #discoverForm { background: url("../img/discover-form.jpg") no-repeat scroll 0 0 #FFF; height:396px; width:616px; position: absolute; top: 0; display: none; } </code></pre> <p>And jQuery code (by @8y5 )</p> <pre><code>$('#joinChoice a').click(function (e) { e.preventDefault(); var $this = $(this); var i = 0; // Reset others var $links = $this.siblings(); $links.removeClass('on'); $links.each(function(linkEl) { $( '#'+$(linkEl).data('form-id') ).hide(); }); // Activate user choice.. $this.addClass('on') $('#'+$this.data('form-id')).show(); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload