0

i keep getting a sytax error when trying to add (function (e) { e.preventDefault; to

$("#pegasus-tile, #o-w, #next-pidu, #prev-bgapp").live('click',     function() {
        $("#proj-content").load("projects/pegasus.html", function() {

        $('<div id="slider" class="nivoSlider"></div>');
        $('#slider').nivoSlider({
            effect: 'sliceUpDown'
        });
    });
});

im not sure how to combine it when using .live, i know its somthing really simple but i just cant get it, any helps much apreciated

antyrat
  • 27,479
  • 9
  • 75
  • 76
sam
  • 9,486
  • 36
  • 109
  • 160
  • 4
    Are you aware that `live` is deprecated? You should be using `on` instead. If you're stuck on an older version of jQuery, you can use `delegate` instead. – James Allardice Jun 22 '12 at 12:18
  • @james i was aware but for some reason using .on dosnt work, im using 1.7.2, is it just a straight forward swap .live for .on or is there more to it ? – sam Jun 22 '12 at 12:23
  • There is more to it - you need to pass a selector as the 2nd argument to `on`. That selector should match an ancestor element to which the event handler will be delegated. – James Allardice Jun 22 '12 at 12:24
  • Read http://api.jquery.com/live/ (scroll down a little) to see how to convert `.live` to `.on` – Blazemonger Jun 22 '12 at 12:24

1 Answers1

1

Its simple:

$("#pegasus-tile, #o-w, #next-pidu, #prev-bgapp").live('click', function( e ) {
    e.preventDefault();
    $("#proj-content").load("projects/pegasus.html", function() {

        $('<div id="slider" class="nivoSlider"></div>');
        $('#slider').nivoSlider({
            effect: 'sliceUpDown'
        });
    });
});
antyrat
  • 27,479
  • 9
  • 75
  • 76