Note that there are some explanatory texts on larger screens.

plurals
  1. POLooking for smart ways to make this Bootstrap/jQuery code "DRY"
    text
    copied!<p>I am looking to reduce this code a little. As usual with jQuery and Bootstrap it is fairly verbose. I would like learn how I can make it more DRY and through the use of what I think will be some combination of arguments and variables the art of re-useable code.</p> <p><strong>NOTE:</strong> These are effectively the same the only real difference is the "content". I will need to make the content and the "placement" unique per instance.</p> <hr> <p><strong>Instance A</strong></p> <pre><code> $('#popover-2').popover({ html: true, trigger: 'manual', placement:'right', container:'body', content:'&lt;h2&gt;EPS Trailing 12 Months&lt;/h2&gt;&lt;p&gt;Vivamus sagittis lacus vel augue laoreet rutrum faucibus #2&lt;/p&gt;' }).click(function(e) { $(this).popover('show'); $('.popover-content').prepend('&lt;a class="close"&gt;&amp;times;&lt;/a&gt;'); $('.close').click(function(e){ $('[data-toggle=popover]').popover('hide'); }); e.preventDefault(); }); </code></pre> <hr> <p><strong>Instance B</strong></p> <pre><code> $('#popover-3').popover({ html: true, trigger: 'manual', placement:'right', container:'body', content:'&lt;h2&gt;EPS Trailing 12 Months&lt;/h2&gt;&lt;p&gt;Vivamus sagittis lacus vel augue laoreet rutrum faucibus #2&lt;/p&gt;' }).click(function(e) { $(this).popover('show'); $('.popover-content').prepend('&lt;a class="close"&gt;&amp;times;&lt;/a&gt;'); $('.close').click(function(e){ $('[data-toggle=popover]').popover('hide'); }); e.preventDefault(); }); </code></pre> <p>Thanks</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