Search code examples
javascriptangularjsangularjs-ng-click

How to send current div's id into a function when clicked


I'm trying to send a div's id into a function as a parameter when clicked.

But it is not working.

Here's what I have written, please take a look :

<div id="currentId" ng-click="functionCalled(id)">
</div>

Solution

  • Edit your code with,
    HTML:

    <button id="bla" class="button button-light" data-ng-click="functionCalled($event)">
        Click Me
    </button>
    

    JS:

    $scope.functionCalled= function(event){
        alert(event.target.id);
    }