M.O.S. Studios Posted October 28, 2010 Share Posted October 28, 2010 I'm using bind to apply a set of listeners on one element at the same time. I want to know if there is a way to have a common var through out all the functions. here is my code: $('.container2 > .item_options:nth-child(3)').click(function(){ playlist.add(season, ($('.container2 > .item_options:nth-child(3)').index(this)), myimages); $('#playlistContainer > div .right').css('display', 'block'); $('#playlistContainer > div:last-child').bind({ mouseover: function(){ var index = $('#playlistContainer > div').index(this); $('#playlistContainer > div:last-child .right').css('display', 'none'); $('#liFC'+index).css('opacity', '.5'); $('#liLC'+index).css('display', 'block'); }, mouseout:function(){ var index = $('#playlistContainer > div').index(this); $('#liFC'+index).css('opacity', '1'); $('#liLC'+index).css('display', 'none'); } }); }); so as you see both mouseout and mouseover have the line var index = $('#playlistContainer > div').index(this); is there any way I can declare that once and reference it easily?? I was thinking adding index: '$('#playlistContainer > div').index(this),' before 'mouseover:' I just don't know how to reference it. any ideas? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/217102-common-var-in-all-of-bind-jquery/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.