Do I have to duplicate this function? - jQuery

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-02-22T19:52:36Z Indexed on 2010/06/05 12:02 UTC
Read the original article Hit count: 201

Filed under:
|
|
|
|

I'm using this function to create an transparent overlay of information over the current div for a web-based mobile app.

Background: using jQTouch, so I have separate divs, not individual pages loading new.

$(document).ready(function() { 
    $('.infoBtn').click(function() {
        $('#overlay').toggleFade(400);
        return false;    
     });
 });

Understanding that JS will run sequentially when i click the button on the first div the function works fine. When I go to the next div if I click the same button nothing "happens" when this div is displayed, but if i go back to the first div it has actually triggered it on this page.

So I logically duplicated the function and changed the CSS selector names and it works for both.

But do I have to do this for each use? Is there a way to use the same selectors, but load the different content in each variation?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery