Note that there are some explanatory texts on larger screens.

plurals
  1. PORework JavaScript Function to make reusable by all Buttons
    text
    copied!<p>Have working JavaScript but I was trying to rework the multiple functions to be one common function so I can reuse as I build dynamic HTML.</p> <p>My attempt has failed - any insight would be appreciated.</p> <p>This is my attempt to make a common function but this doesn't work:</p> <pre><code>&lt;script type='text/javascript'&gt;//&lt;![CDATA[ $(window).load(function(){ $(document).ready(function() { $('#'+ this.id +'Div').hide(); $('button#'+ this.id).click(function() { $('#'+ this.id +'Div').toggle(400); }); }); });//]]&gt; &lt;/script&gt; </code></pre> <p>This is the functions that are working that I am trying to replace with above</p> <pre><code>&lt;script type='text/javascript'&gt;//&lt;![CDATA[ $(window).load(function(){ $(document).ready(function() { $('#hideDetails1Div').hide(); $('button#hideDetails1').click(function() { $('#hideDetails1Div').toggle(400); }); }); $(document).ready(function() { $('#hideDetails2Div').hide(); $('button#hideDetails2').click(function() { $('#hideDetails2Div').toggle(400); }); }); $(document).ready(function() { $('#hideDetails3Div').hide(); $('button#hideDetails3').click(function() { $('#hideDetails3Div').toggle(400); }); }); });//]]&gt; &lt;/script&gt; </code></pre> <p>Button hooked to function that hides an associated DIV</p> <pre><code>&lt;button id="hideDetails1" title="" class="primaryButton2"&gt;show box 1&lt;/button&gt; .... &lt;br /&gt; &lt;!-- hide div --&gt; &lt;div id="hideDetails1Div" style="border:1px solid red; width:300px; height:100px;"&gt; &lt;h2&gt;box 1&lt;/h2&gt; &lt;/div&gt;&lt;!-- END OF HIDE DIV --&gt; </code></pre>
 

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