1

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">&nbsp;</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

1 Answer 1

2

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')

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

1 Comment

yes, perfect thx. I know not supposed to do this but it might allow us to start using angular which would be cool

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.