Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are using a non-unique id. It will only ever give you the first one.</p> <pre><code>&lt;a href="#" class="button" data-modal="1"&gt;Click 1&lt;/a&gt; &lt;div id="modal"&gt; &lt;div id="heading"&gt;Content form 1&lt;/div&gt; &lt;/div&gt; &lt;a href="#" class="button" data-modal="2"&gt;Click 2&lt;/a&gt; &lt;div id="modal"&gt; &lt;div id="heading"&gt;Content form 2&lt;/div&gt; &lt;/div&gt; &lt;!--jQuery--&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="js/jquery.reveal.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $('.button').click(function (e) { // Button which will activate our modal $('#modal' + $(this).data('id')).reveal({ // The item which will be opened with reveal animation: 'fade', // fade, fadeAndPop, none animationspeed: 600, // how fast animtions are closeonbackgroundclick: true, // if you click background will modal close? dismissmodalclass: 'close' // the class of a button or element that will close an open modal }); return false; }); }); &lt;/script&gt; </code></pre> <p>Observer how:</p> <ol> <li>I added a number behind each of your modal id's.</li> <li>How I added an attribute called "data-id" to each link with the corresponding number we want.</li> <li>How I used jQuery's wonderful data() method to get that corresponding number.</li> </ol> <p>The advantage of this method is that the links can be moved to wherever they need to be without needing to change the internals of the click event. Aka we do not need to do DOM searching via <code>.next()</code>, <code>.parent()</code>, <code>.find()</code> etc.</p>
 

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