How to empty the content of an element using AngularJS ? Last Updated : 06 Sep, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to remove the content of an element in HTML DOM using AngularJS. This task can be accomplished by implementing the jQuery empty() method that removes all child nodes and their content for the selected elements. Syntax: element.empty();Parameter: This method does not accept any parameter. Return Value: This method returns the selected element with the specified changes made by the empty() method. Approach: First select the element whose content is to be emptied. Then use the empty() method to remove the content of the element. Example 1: In this example, the content of the element of ID('div') is emptied. HTML <!DOCTYPE html> <html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module('app', []); myApp.controller('controller', function ($scope) { $scope.emptyEl = function () { var el = angular.element(document.querySelector('#div')); el.empty(); }; }); </script> <style> #div { height: 80px; width: 170px; margin: 0 auto; background: green; color: white; } </style> </head> <body style="text-align: center"> <h1 style="color: green"> GeeksforGeeks </h1> <h3> Empty the content of an element </h3> <div id="div"> GeeksforGeeks <br /> A Computer Science portal </div><br /> <div ng-app="app"> <div ng-controller="controller"> <input type="button" value="Click here" ng-click="emptyEl()" /> </div> </div> </body> </html> Output: Example 2: In this example, the content of an element along with its children are emptied. HTML <!DOCTYPE HTML> <html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function ($scope) { $scope.emptyEl = function () { var el = angular.element( document.querySelector('#div')); el.empty(); }; }); </script> <style> #div { height: 80px; width: 170px; margin: 0 auto; background: green; color: white; } #div2 { background: blue; margin: 10px; } </style> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Empty the content of an element </h3> <div id="div"> <h4>This is parent element</h4> <div id="div2"> This is child element </div> </div><br> <div ng-app="app"> <div ng-controller="controller"> <input type="button" value="Click here" ng-click="emptyEl()"> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to empty the content of an element using AngularJS ? P PranchalKatiyar Follow Improve Article Tags : Web Technologies AngularJS CSS-Questions AngularJS-Questions Similar Reads How to push elements in an array using AngularJS ? Given an array and the task is to perform the push operation on the array using AngularJS. The arr.push() method is used to push one or more values into the array, & new values will add at the end of an array. This method changes the length of the array by the number of elements added to the arr 2 min read How to Delete a Row from Table using AngularJS ? Given a HTML table and the task is to remove/delete the row from the table with the help of AngularJS.Approach: The approach is to delete the row from the array where it stored and served to the table data. When the user clicks on the button near to the table row, it passes the index of that table a 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 make empty an array using AngularJS ? Given an array & the task is to make empty an array or delete all the elements from the array in AngularJS. In order to do this, there are 2 ways i.e., either use the [] notation to reinitialize the array which eventually removes all the elements from the array, or set the length of the array to 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 clear the content of a div using JavaScript? JavaScript provides the functionality of clearing the content of div. There are two methods to perform this function, one by using the innerHTML property and other by using the firstChild property and removeChild() method. Below are the approaches used to clear the content of a div using JavaScript: 3 min read How to remove contents of elements using jQuery ? In this article, we will discuss how to remove the contents of the elements using jQuery. To remove the contents of elements, we will use the empty() method and the remove() method. The jQuery empty() method is used to remove all child nodes and their content for the selected elements. This method d 3 min read How to get input value search box and enter it in AngularJS component using Enter key ? In this article, we will see how to get an input value entered in the search box using Enter key in AngularJS. To implement a search component in AngularJS that calls the function whenever the user presses the enter key(keyCode = 13) and then does some relatable task from the user input. This can be 3 min read Remove duplicate elements from an array using AngularJS We have given an array and the task is to remove/delete the duplicates from the array using AngularJS.Approach: The approach is to use the filter() method and inside the method, the elements that don't repeat themselves will be returned and the duplicates will be returned only once.Hence, a unique a 2 min read How to delete an element from an array using JavaScript ? The array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index. In this article, we will discuss different ways to remove elements from the array. 5 min read Like