5

I tried the below code but it is not working

<script type="text/javascript">
    $(document).ready(function () {
        $('body').on('click', '.pg_previous,.pg_next', function () {
            jQuery("img.lazy").lazy({});
            alert('ddsda');
        });
    });
</script>

Jquery 1.9.1

Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

2 Answers2

11

here try this:

<script type="text/javascript">
$(function(){
    $('body').on('click', '.pg_previous,.pg_next', function () {
        jQuery("img.lazy").lazy({});
        alert('ddsda');
    });
});
</script>
RicardoE
  • 1,665
  • 6
  • 24
  • 42
  • This did it for me! Thank you! Attaching the click event to the parent element and selecting its children is the most efficient way. – Stephen Rodriguez Jul 11 '14 at 14:12
  • 2
    both are equivalent, but for this particular version of jQuery I often found the long version doesn't work, and the shortcut do. – RicardoE Oct 27 '14 at 20:40
3

You forgot the DOM ready handler

Encase your code inside the ready handler and should work fine unless you have any errors showing up in our console.

$(function() {
    // Your code here
});
Sushanth --
  • 55,259
  • 9
  • 66
  • 105