Banshee
Banshee

Reputation: 15807

Unbind mouseout event in jquery?

Hi!

I got the following code :

function UpdatePriceSubscribeButton() {

    if (_userPriceSubscribe > 0) {
        $("#btUpdatePriceSubscribing").removeClass("con");
        $("#btUpdatePriceSubscribing").addClass("conActive");
        $("#btUpdatePriceSubscribing").unbind('onmouseover').unbind('onmouseout');
    }
    else {
        $("#btUpdatePriceSubscribing").removeClass("conActive");
        $("#btUpdatePriceSubscribing").addClass("con");
        $("#btUpdatePriceSubscribing").mouseover(function() { this.className = 'conActive'});
        $("#btUpdatePriceSubscribing").mouseout(function() {this.className = 'con'});
    }
};

The problem with this is that when onmouseout the class will be changed even if the _userPriceSubscribe was set to 1?

What Im trying to do here is to change the current class and the hover class on client side with jquery.

Edit1: I have also troed $("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave'); that is sugested here : http://api.jquery.com/hover/

Edit2: This works :

function UpdatePriceSubscribeButton() {

    if (_userPriceSubscribe > 0) {
        $("#btUpdatePriceSubscribing").removeClass("con");
        $("#btUpdatePriceSubscribing").addClass("conActive");
        $("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave');
    }
    else {
        $("#btUpdatePriceSubscribing").removeClass("conActive");
        $("#btUpdatePriceSubscribing").addClass("con");

        $("#btUpdatePriceSubscribing").hover(function () { this.className = 'conActive' }, function () { this.className = 'con' });
    }
};

But is this a good way of doing it?

BestRegards

Upvotes: 1

Views: 3041

Answers (3)

Banshee
Banshee

Reputation: 15807

This solved my problem :

function UpdatePriceSubscribeButton() {

    if (_userPriceSubscribe > 0) {
        $("#btUpdatePriceSubscribing").removeClass("con");
        $("#btUpdatePriceSubscribing").addClass("conActive");
        $("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave');
    }
    else {
        $("#btUpdatePriceSubscribing").removeClass("conActive");
        $("#btUpdatePriceSubscribing").addClass("con");

        $("#btUpdatePriceSubscribing").hover(function () { this.className = 'conActive' }, function () { this.className = 'con' });
    }
};

Upvotes: 0

mikos
mikos

Reputation: 424

The event name is mouseenter not omouseenter. So, unless omouseenter is a custom event, you'll want to change this line:

$("#btUpdatePriceSubscribing").unbind('omouseenter mouseleave');

to:

$("#btUpdatePriceSubscribing").unbind('mouseenter mouseleave');

Upvotes: 1

phtrivier
phtrivier

Reputation: 13361

Would it make sense to set up one onmouseout / onmouseover handler that looks for the price inside the mouseout handler ?

$("#btUpdatePriceSubscribing").mouseover(function () {
   if (_userPriceSubscribe > 0) {
       this.className = "..."
   }
}

(Otherwise I'm not sure I get what you're trying to do...)

Upvotes: 1

Related Questions