How to get original element from ng-click in AngularJS ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In AngularJS, we can get the original DOM element that fired the ng-click event using the event's currentTarget property. Getting the event's currentTarget can be useful when we want to track an element's activity, in this case, whether and how many times a particular element is clicked, or we want to perform a certain operation if a particular element in the DOM gets clicked. In this article, we will see how to get the original element from ng-click in AngularJS. There are 2 approaches to get the original element by implementing the ng-click Directive: Table of Content Implementing the currentTarget PropertyImplementing the target Property Implementing the currentTarget PropertyIn this approach, we will use the currentTarget property of an event to get the original element that triggered the click event from the ng-click directive. The following steps will be followed: Create an AngularJS project using the CDN: Create an AngularJS project using the AngularJS CDN. You can name the app "my-app".Include the Angular CDN script and create a base layout: Include the Angular CDN script in the HTML file and add a div and button inside the body tag.Add the AngularJS controller to the script: Create an AngularJS controller, and inside the controller, access the event's currentTarget property to get the original element that triggered the ng-click event.Example: This example illustrates the basic implementation to get the original element from the ng-click Directive. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <script> angular.module('myApp', []).controller( 'gfgCtrl', function ($scope) { $scope.myFunction = function (event) { const originalElement = event.currentTarget; console.log('originalElement!', originalElement); }; }); </script> </head> <body style="text-align: center;"> <div ng-app="myApp" ng-controller="gfgCtrl"> <div ng-click="myFunction($event)"> <button>Click me</button> </div> </div> </body> </html> Output: The output should log the original element that triggered the ng-click event to the console. Implementing the target Property In this approach, we will use the target property of an event to get the element that triggered the click event. Here, we will create an <h1> and <p> element and on the click of the paragraph element, we will log the element to the console, as well as change its background color. Now, we will use the controller logic and modify it to use the target property of the event to get the target element on click of it and change the background color of the paragraph element. Example: This example demonstrates getting the original element from ng-click by implementing the target Property. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <script> angular.module('myApp', []).controller( 'gfgCtrl', function ($scope) { $scope.myFunction = function (event) { const originalElement = event.target; originalElement.style.backgroundColor = 'red'; console.log('originalElement!', originalElement); }; }); </script> </head> <body style="text-align: center;"> <div ng-app="myApp" ng-controller="gfgCtrl"> <div ng-click="myFunction($event)"> <h1>GeeksforGeeks</h1> <p> Click here to change the background color of this paragraph </p> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get original element from ng-click in AngularJS ? D dishebhbhayana Follow Improve Article Tags : Web Technologies AngularJS Geeks Premier League AngularJS-Questions Geeks Premier League 2023 +1 More Similar Reads How to Scroll to an Element on click in Angular ? In this article, we will see how to scroll to an element on click in Angular. Here, we will create a component that enables scrolling to specific targets when a button is pressed within the document from one target to another.Steps for Installing & Configuring the Angular ApplicationStep 1: Crea 4 min read How to show a span element for each rows clicked in AngularJS ? In this article, we will see how to display a span element for each row clicked in AngularJS. A span element is used to group in-line elements in a document. It can be used to make a hook to a particular part of the document which may be subject to a particular action based on DOM events. The span e 4 min read How to call a function on click event in Angular2 ? A Function is a set of statements that takes input, does some specific computation, and produces output. An on click event occurs when the user clicks on an element. In this article, we will see How to call a function on click event in Angular2, along with understanding the basic implementation thro 3 min read How to select an element by its class name in AngularJS? Given an HTML document and the task is to select an element by its className using AngularJS. The elements can be selected with the help of a class name using the document.querySelector() method that is used to return the first element that matches a specified CSS selector(s) in the document. Approa 2 min read How to Remove HTML element from DOM using AngularJS ? In this article, we will see how to remove particular HTML elements from the DOM with the help of AngularJS, along with understanding its implementation through the examples. For this, we can use the remove() method that helps to remove all the selected elements including all the text. Syntax: selec 2 min read How to get form input value using AngularJS ? Given a form element and the task is to get the form values input by the user with the help of AngularJS.Approach: We are storing the data in the JSON object after the user enters it in the input element with the help of the Angular.copy(object) method. After that, data from the JSON object can be a 2 min read How to directly update a field by using ng-click in AngularJS ? In this article, we will see how to update the field directly with the help of the ng-click directive in AngularJS, along with understanding different ways to implement it through the implementations. Any field can be updated with ng-click using a custom JavaScript function. For this, we can make a 3 min read How to delete an item or object from the array using ng-click ? The task is to delete the item from the list when the button is clicked. This all should be done by using ng-click. This is done by using the splice() method. The syntax for the method is given below. Syntax for splice() function: array.splice(indexno, noofitems(n), item-1, item-2, ..., item-n) Exam 2 min read How to get file content and other details in AngularJS? We can get the file content by using some basic angular functions and other details like the name and size of the file in AngularJS. To understand it look into the below example where both HTML and JS files are implemented. Note: Consider below two files are of same component in angular. app.module. 2 min read How to detect click event outside Angular component ? In angular, clicks are detected by different ways. As click is an event, thus inside a component it is detected by simple event binding. A simple click via event binding for detection within the component is given as follows: javascript @Component({ selector: "geeks", template: ` <h1 (c 4 min read Like