Reputation: 19969
I know this is bad design but would like to introduce angular to a current project. I would like sayHello to be able to determine whether the element has the class 'is-a-favorite'
<div ng-click="sayHello(29, $event)" class="is-a-favorite" data-type="location" data-global-id="29" data-make-disappear="false"> </div>
$scope.sayHello=function(global_id,event){
//var selector=???
if(selector.hasClass('is-a-favorite')){
console.log("this is-a-favorite");
}
};
How would (or could) I get a reference to current DOM element to query via hasClass?
thx
Upvotes: 1
Views: 346
Reputation: 1490
The clicked element is available as $event.target
, so you could check $($event.target).attr('class')
or something similar.
EDIT: actually, what you'd want is to check $($event.target).hasClass('is-a-favorite')
Upvotes: 2