?
Solved

jquery keep two buttons in the same state

Posted on 2012-04-13
4
Medium Priority
?
235 Views
Last Modified: 2012-05-07
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'));
            });
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37844531
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/
0
 

Author Comment

by:jackjohnson44
ID: 37844552
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().
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37844664
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.
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 2000 total points
ID: 37845723
//untested but does this work:

$(".actionButton").blur(function () {
                $(".actionButton").not(this).blur();
                console.log("blur.button=", $(this).attr('id'));
            });
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question