View Single Post
Old 11-10-2011, 11:25 AM   PM User | #1
fishbaitfood
New Coder

 
Join Date: Nov 2011
Posts: 30
Thanks: 5
Thanked 0 Times in 0 Posts
fishbaitfood is an unknown quantity at this point
[jQuery] MouseDown and Up when toggle-ing

Hi all,

I have working toggle labels for adding/removing table rows.
These labels have a sprite checkbox background, which holds 4 different states:
- unchecked
- unchecked-highlight
- checked
- checked-highlight

These states need to appear when pressing and releasing a label, so mousedown and mouseup.
However, with the code below, there is no background change at all.
I've used classes for the different background-positions.

Code:
$("ul.checklist label").mousedown(function() {
	if ($(this).hasClass("checked")) {
		$(this).removeClass("checked").addClass("checked-highlight");
	}
	else if ($(this).hasClass("unchecked")) {
		$(this).removeClass("unchecked").addClass("unchecked-highlight");
	}
});

$("ul.checklist label").mouseup(function() {
	if ($(this).hasClass("checked-highlight")) {
		$(this).removeClass("checked-highlight").addClass("checked");
	}
	else if ($(this).hasClass("unchecked-highlight")) {
		$(this).removeClass("unchecked-highlight").addClass("unchecked");
	}
});

$("ul.checklist label").toggle(
	function() {
		$(this).removeClass("unchecked").addClass("checked");
		$(this).prev().attr("checked", true);
	}, function() {
		$(this).removeClass("checked").addClass("unchecked");
		$(this).prev().attr("checked", false);
	}
);
How do I make the mousedown and mouseup functions work?

Thanks already.
fishbaitfood is offline   Reply With Quote