[jQuery] how to call a toggle on .blur
i have a search icon at the top of my page, when i click this it toggles show/hide on the search form. now when the user loses focus of the search form (.blur), i want it to activate the hide part of the toggle. when the search icon is clicked, it gives focus to the search form, so the moment the icon is clicked, the search form gains focus, then when someone clicks somewhere else on the page and the form loses focus, i want the search form to hide. the problem is, if i just have the search form hide on .blur, then when you click the search icon and then click somewhere else and the search form loses focus, and then you click the icon to show the search form again, it will hide the search form(to the user, it looks like it didn't do anything, since the search form is already hidden). so after 2 clicks on the icon, then, it finally shows the search form again. Here's my code: .searchbutton is the search icon mentioned above. and #search is my Search Form mentioned above. Code: $('.search_button').toggle( function () { $('#search') .stop().animate({"left":"-5px"}, function() {$('#search').focus ();}) }, function () { $('#search') .stop() .animate({"left":"230px"}, 300); }); how do i get it so that when the search form looses focus(.blur), it toggles. How do i do this without breaking the toggle?
[jQuery] multiple conditions?
I have a div with a textbod inside of it. When both of these lose focus, so the focus is not on either of them, then I want the div to move. How would I write the code that if both of these lose focus, THEN do whatever i want. I just want to know how to have 2 selectors, and when both of them lose focus, then do something. i'm probably missing the obvious... it's been a long day. thanks!
[jQuery] Re: multiple conditions?
hey i tried that, and it didn't work. I played around with it for awhile trying everything i could, but to no avail :( any ideas? Ami wrote: > var divFocus=false,textareaFocus=false > $('div').focus(function () {divFocus=true}).blur(function() > {divFocus=false;doSomething()}; > $('textarea').focus(function () {textareafocus=true}).blur(function() > {textareaFocus=false;doSomething()} > > function doSomthing() > { > if (!divFocus && !textAreaFocus) alert('There is no focus on the > div&textarea') > } > > Hope it's help you. > Aminadav > > On Mar 2, 4:38 am, "homien...@gmail.com" wrote: > > I have a div with a textbod inside of it. When both of these lose > > focus, so the focus is not on either of them, then I want the div to > > move. How would I write the code that if both of these lose focus, > > THEN do whatever i want. > > I just want to know how to have 2 selectors, and when both of them > > lose focus, then do something. > > i'm probably missing the obvious... it's been a long day. > > thanks!
[jQuery] lose focus on txtbox and div, do something
I have a div with a textbod inside of it. When both of these lose focus, so the focus is not on either of them, then I want the div to move. How would I write the code that if both of these lose focus, THEN do whatever i want. I just want to know how to have 2 selectors, and when both of them lose focus, then do something. Ami gave me this code but it doesn't seem to be working, can someone help me out? var divFocus=false,textareaFocus=false $('div').focus(function () {divFocus=true}).blur(function() {divFocus=false;doSomething()}; $('textarea').focus(function () {textareafocus=true}).blur(function() {textareaFocus=false;doSomething()} function doSomthing() { if (!divFocus && !textAreaFocus) alert('There is no focus on the div&textarea') }
[jQuery] Re: lose focus on txtbox and div, do something
anyone? On Mar 5, 3:27 pm, "homien...@gmail.com" wrote: > I have a div with a textbod inside of it. When both of these lose > focus, so the focus is not on either of them, then I want the div to > move. How would I write the code that if both of these lose focus, > THEN do whatever i want. > I just want to know how to have 2 selectors, and when both of them > lose focus, then do something. > > Ami gave me this code but it doesn't seem to be working, can someone > help me out? > > var divFocus=false,textareaFocus=false > $('div').focus(function () {divFocus=true}).blur(function() > {divFocus=false;doSomething()}; > $('textarea').focus(function () {textareafocus=true}).blur(function() > {textareaFocus=false;doSomething()} > > function doSomthing() > { > if (!divFocus && !textAreaFocus) alert('There is no focus on the > div&textarea') > > }