Note that there are some explanatory texts on larger screens.

plurals
  1. PONot having to repeat script every time in loop
    primarykey
    data
    text
    <p>I have the following script that happens within a loop. How would I make it so I only have to place it once at the bottom of a page and not have the classes hard coded in? The script occurs for each <code>&lt;li&gt;</code> which seems very clunky.</p> <p>Here's the script</p> <pre><code> &lt;script&gt; $(".&lt;?php echo strtolower(get_field('code'));?&gt;_btn").click(function(){ $("#&lt;?php echo strtolower(get_field('code'));?&gt;").on('show', function () { $('iframe.fohl-mobile').attr("src","http://www.psfk.com/home#&lt;?php echo get_field('code');?&gt;"); }); }); &lt;/script&gt; </code></pre> <p>Here's the whole piece that repeats in the loop</p> <pre><code> &lt;li&gt; &lt;a data-toggle="modal" role="button" class="&lt;?php echo strtolower(get_field('code'));?&gt;_btn" href="#&lt;?php echo strtolower(get_field('code'));?&gt;"&gt;&amp;nbsp;&lt;/a&gt; &lt;img class="lazy" alt="&lt;?php the_title();?&gt;" src="&lt;?php echo site_url('wp-content/fohl/holder.png');?&gt;" data-original="&lt;?php echo site_url('/wp-content/fohl/products/').strtolower(get_field('code'));?&gt;.png" /&gt; &lt;noscript&gt;&lt;img src="&lt;?php echo site_url('/wp-content/fohl/products/').strtolower(get_field('code'));?&gt;.png” alt="&lt;?php the_title();?&gt;"/&gt;&lt;/noscript&gt; &lt;div class="title"&gt;&lt;?php the_title();?&gt; &lt;div id="&lt;?php echo strtolower(get_field('code'));?&gt;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;iframe class="fohl-mobile" height="500" width="330" frameborder="0" src=""&gt;&lt;/iframe&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; $(".&lt;?php echo strtolower(get_field('code'));?&gt;_btn").click(function(){ $("#&lt;?php echo strtolower(get_field('code'));?&gt;").on('show', function () { $('iframe.fohl-mobile').attr("src","&lt;?php echo site_url('/home#'.get_field('code'));?&gt;"); }); }); &lt;/script&gt; &lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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