Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/217102-common-var-in-all-of-bind-jquery/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.