Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  66] [ 3]  / answers: 1 / hits: 20845  / 10 Years ago, wed, april 16, 2014, 12:00:00

With the answer of my previous question, Textarea highlight on focus, I discovered an alternative to onfocus and onblur. These are onfocusin and onfocusout.



My question is, is there any differences between the two with how they behave?



This fiddle demonstrates that both appear the same: http://jsfiddle.net/spedwards/pQLAM/


More From » javascript

 Answers
6

focus and blur events do not bubble, so event delegation is impossible with those events.



focusin and focusout bubbles to the parent elements, and can be delegated.



Otherwise they are the same, but focusin and focusout is not part of any standard, but are in fact proprietary IE events, later adopted by some other browsers, but they are not supported cross browser.



Example



<div id=test>
<input type=text />
</div>


with js



var div = document.getElementById('test');

div.addEventListener('focus', handler, false); // does not work, focus does not bubble

div.addEventListener('focusin', handler, false); // works when input is focused, as the event bubbles


FIDDLE


[#71433] Tuesday, April 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
elishaannac questions
Sun, Dec 5, 21, 00:00, 3 Years ago
Mon, Jun 14, 21, 00:00, 3 Years ago
Mon, Jul 22, 19, 00:00, 5 Years ago
Mon, Jul 8, 19, 00:00, 5 Years ago
;