ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

jQuery question: binding events interrupts the script?

August 26, 2008 12:22pm

Subscribe [2]
  • #1 / Aug 26, 2008 12:22pm

    Brian M.

    529 posts

    Wondering if someone might help with a quick jQuery question. Is binding an event supposed to stop/interrupt the script?  I’ve got this:

    function bindNewLinks() { // rebind the new DOM element so clicks will clicky!
        
        $("#largerImg").bind("click", loadBigImage()); 
        $("#prevLink, #nextLink").bind("click", linkNextPrev());
    
    }

    And I can only get the first bind to work -anything after it doesn’t ever execute, doesn’t matter if it’s a bind, an alert, anything.  I’ve tried wrapping the second bind into a callback function within the first and that doesn’t work either.

    Is this functioning properly? It sure doesn’t seem like it. I just want to make sure I’m understanding how binding works before I keep trying to track down wtf is going on with my script(s). It seems very strange because binding doesn’t actually fire the event, you need to trigger it to fire it…

    Thanks for any help.

  • #2 / Aug 26, 2008 3:14pm

    plank

    30 posts

    not a jquery expert (i lean towards yui), but it looks like you are executing the callback, as opposed to passing it in.

    try defining your loadBigImage like

    var loadBigImage = function(){

    };

    $(”#largerImg”).bind(“click”, loadBigImage);

  • #3 / Aug 27, 2008 1:15am

    Brian M.

    529 posts

    I tried that actually and didn’t have any luck - I’ll look back into it again though. I’ve figured out a way to do it without needing to rebind anything so I might do that temporarily until I can afford to spend more time messing around with it. I do end up having syntax problems not infrequently since it’s been along time since I’ve messed with javascript and I’m new to jQuery. I still can’t quite figure out the best way to do a couple more complex selectors properly like:  select all links with class thumbnail that don’t contain class currentThumb for example.

    Thanks 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases