10 examples of 'javascript remove element by class' in JavaScript

Every line of 'javascript remove element by class' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
53function removeElementByClassName(className) {
54 // Removes an element from the document
55 var elements = document.getElementsByClassName(className);
56 for (let elem of elements) {
57 elem.parentNode.removeChild(elem);
58 }
59}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

91function removeAllElementClass(className){
92 $("."+className, window.parent.document).removeClass(className);
93}
47function removeClassName(elementArray, className) {
48 elementArray.forEach(element => {
49 element.classList.remove(className)
50 })
51}
1export function removeFromElementClassIfContains(element, className) {
2 const classList = element.classList;
3 if (classList.contains(className)) {
4 classList.remove(className);
5 }
6}
921function remove_class(css_class, element) {
922 check_params(css_class, element, "remove_class");
923 var regexp = new RegExp("(\\s" + css_class + ")|(" + css_class + "\\s)|" + css_class, "i");
924 element.className = pklib.string.trim(element.className.replace(regexp, ""));
925}
46function removeElementById(elementId) {
47 // Removes an element from the document
48 var element = document.getElementById(elementId);
49 if(element != null)
50 element.parentNode.removeChild(element);
51}
47function removeElementByID(elementID) {
48 var elem = document.getElementById(elementID);
49 if (elem != null) {
50 elem.parentNode.removeChild(elem);
51 return true;
52 }
53 return false;
54}
5export function removeElement(domSelector) {
6 $(domSelector).remove();
7}
172function remove_element ( selector ) {
173 $(selector).remove ();
174}
109function removeClass(element, className) {
110 if (hasClass(element, className)) {
111 if (element.classList) {
112 element.classList.remove(className);
113 } else {
114 element.className = (' ' + element.className + ' ')
115 .replace(' ' + className + ' ', ' ').trim();
116 }
117 }
118 return element;
119}

Related snippets