Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

jquery keep two buttons in the same state

I have two buttons that I want to keep in the same state so when one is blurred, the other is too.  When I try to do this, I get in an endless loop and the browser crashes. I think I only need to blur the other button if it is not already blurred.

this is in a plugin, so $element refers to the parent div

<div><a href="" class="actionButton>select</a><a href="" class="actionButton>arrow</a></div>

            $(".actionButton").blur(function () {
                $(".actionButton").blur();
                console.log("blur.button=", $(this).attr('id'));
            });
Avatar of basicinstinct
basicinstinct
Flag of Australia image

i wouldn't take this approach.

instead handle the event on the containing div then perform the action on all of the buttons, like this : http://jsfiddle.net/FpFmh/2/
Avatar of jackjohnson44
jackjohnson44

ASKER

Thanks, but I am actually using jquery button() to create the button.  I am using a split button like in this example, which has two divs and the second one has an icon.  The good thing about this method is that all my other buttons have enable and disable functions from button().  

http://jqueryui.com/demos/button/#splitbutton

I am really close to being done and don't want another button plugin.  There are other reasons I need button().
hmm, not quite sure i understand how the above solution doesn't solve your problem. i can't see button() anywhere in your code. maybe i just haven't had enough sleep.


this is closer to what you were trying to do in the code you posted but solves the infinite looping problem:

http://jsfiddle.net/skxuH/1/

I still think you should just delegate the event handling to a container tho.
ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial