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 <li>
which seems very clunky.
Here's the script
<script>
$(".<?php echo strtolower(get_field('code'));?>_btn").click(function(){
$("#<?php echo strtolower(get_field('code'));?>").on('show', function () {
$('iframe.fohl-mobile').attr("src","http://www.psfk.com/home#<?php echo get_field('code');?>");
});
});
</script>
Here's the whole piece that repeats in the loop
<li>
<a data-toggle="modal" role="button" class="<?php echo strtolower(get_field('code'));?>_btn" href="#<?php echo strtolower(get_field('code'));?>"> </a>
<img class="lazy" alt="<?php the_title();?>" src="<?php echo site_url('wp-content/fohl/holder.png');?>" data-original="<?php echo site_url('/wp-content/fohl/products/').strtolower(get_field('code'));?>.png" />
<noscript><img src="<?php echo site_url('/wp-content/fohl/products/').strtolower(get_field('code'));?>.png” alt="<?php the_title();?>"/></noscript>
<div class="title"><?php the_title();?>
<div id="<?php echo strtolower(get_field('code'));?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<iframe class="fohl-mobile" height="500" width="330" frameborder="0" src=""></iframe>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
<script>
$(".<?php echo strtolower(get_field('code'));?>_btn").click(function(){
$("#<?php echo strtolower(get_field('code'));?>").on('show', function () {
$('iframe.fohl-mobile').attr("src","<?php echo site_url('/home#'.get_field('code'));?>");
});
});
</script>
</li>