I need to retrieve the DOM element that causes a focusout (blur) event from WITHIN the blur event. The following code will give me the ID of the element that lost focus, NOT the element that caused the element to lose focus. It is that second element that I need.
.live('blur', function(e) {
var id = $(this).attr('id');
}
How do I get the element that caused the blur, not the element the blur is attached to? The only way I can think of is to capture the window.click event and then handle the logic I need there, but that will get tricky so I am hoping there is a way to get the DOM element from within the blur event.
With this:
$(document).click(function(event) {
window.lastElementClicked = event.target;
});
Cheers
Run this
$(document).click(function(e) {
e = e || event;
$.lastClicked = e.target || e.srcElement;
});
then you can get it anywhere by
var lastClickedElement = $.lastClicked;
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With