Gaurav Aggarwal Gaurav Aggarwal - 6 months ago 35
Javascript Question

Angularjs issue in getting id of clicked element

I am trying to get id of the clicked element in angularjs and it is working quite fine. Below is my code


<a href="#faqinner/contactform" class="clearfix" ng-click="getCateId($event)" id="{{}}">
<span class="icon">
<img ng-if="option.icon!=null" ng-src="{{option.icon}}">
<img ng-if="option.icon==null" ng-src="">
<span class="faq_name">{{}}</span>
<span class="arrow">
<img src="images/right_arrow.png">


$scope.getCateId = function(obj, $event){
$rootScope.cateId =;

The above code should return the id of the clicked
tag but the problem i am facing is there is more
tag so when i click on the space of span it target's the
tag which has no id but when i specifically click on the top free space where no inner
covered then it works fine.

How can i get the id of
even if i click on


You just need to pass the to ngClick handler

<a  ng-click="getCateId(" id="{{}}">

controller method

$scope.getCateId = function(optionId){