0

As given in this answer, We need to pass and $event object to the ng-click function, and access the target element using

$scope.setMaster = function(obj, $event){
    console.log($event.target);
}

While event.target isn't a cross-browser property. To overcome this, quirksmode suggests the following

function doSomething(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
}

Is there any other/better way of getting target element? Like when we bind using DOM/jQuery method, we can use this keyword to refer to clicked element.

Please suggest.

1 Answer 1

1

As a library, angularjs does this normalization so there is no need to do the browser specific code our self. it is handled within the library.

The event object passed to the click handler is normalized and will have the said properties irrespective of the browser(given the said browser is supported by the library)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.