Programming i html: How can tell I which element i clicked on to trigger a blur event handler? on newest questions tagged html – Stack Overflow

Quite simple. I have a blur() event handler that fires a function, I want the function not to fire when the blur is triggered by the click on a certain element.

I tried document.activeElement but i get a HTMLBodyElement instead of the element I click on.

code:

$j(".input_filtrare_camp").blur(
    function(event) {
    nr_img = this.parentNode.id.split("_")[1];
    //alert(document.activeElement);
    if(document.activeElement.id.indexOf("img_exact") < 0) //run only if the id of the element I clicked on doesn't contain "img_exact"
        enter_input_filtrare(event.target);
});

the alert is for troubleshooting, of course.

I used techfoobar’s solution as follows:

var currElem = null;

$(document).mousedown(function(e) {
    currElem = e.target;
});

$j(".input_filtrare_camp").blur(
    function(event) {
    nr_img = this.parentNode.id.split("_")[1];
    if(currElem.id.indexOf("img_exact") < 0) //run only if the id of the element I clicked on doesn't contain "img_exact"
        enter_input_filtrare(event.target);
});

Check out PointedEars’ answer for some important information regarding this issue.

See Answers


source: http://stackoverflow.com/questions/10794706/how-can-tell-i-which-element-i-clicked-on-to-trigger-a-blur-event-handler
Programming i html: programming-i-html



online applications demo