The World’s Largest Online Community for Developers

'; javascript - How to remove/add html tag in ng-repeat - LavOzs.Com

is it possible to remove/add the html tag dynamically with condition in the javascript?

Example i need to remove the number 2 th column when button is clicked, insert back again when button is clicked. I have using this but does not work.

angular.element(document).find('.dataTable tfoot').remove($scope.items);///to remove
angular.element(document).find('.dataTable thead').prepend($scope.items);//to add

According to the Angular documentation on angular.element().find():

Note: Keep in mind that this function will not find elements by tag name / CSS selector. For lookups by tag name, try instead angular.element(document).find(...) or $document.find(), or use the standard DOM APIs, e.g. document.querySelectorAll().

So, angular.element(document).find(...) can only be used lookup by tag name not class name. Therefore, your code is not working because your .find() is not returning the element(s) you expect it to (in fact it's not returning any).

Use the DOM method getElementsByClassName to select using class name:

const dataTable = angular.element(document.getElementsByClassName("dataTable"));

Then you can perform your prepends or removals on the wrapped angular dataTable element:

dataTable.remove($scope.items); //to remove
dataTable.prepend($scope.items); //to add
How do JavaScript closures work?
Add table row in jQuery
How do I check if an element is hidden in jQuery?
How do I remove a property from a JavaScript object?
How do I redirect to another webpage?
How do I check whether a checkbox is checked in jQuery?
How do I include a JavaScript file in another JavaScript file?
How to check whether a string contains a substring in JavaScript?
How can I remove a specific item from an array?
How do I return the response from an asynchronous call?