Get Class List For An Element With JavaScript

For More Videos Visit Our YouTube Channel




Here we consider how to Get Class List For An Element With JavaScript. Suppose we have a Div with multiple Classes as shown below.

Get Class List For Element With JavaScript, Get Class List For Element With Jquery, Get Class List For Element, Get Class List For Div, Get Class List For Table, Get Class List For Link, Get Class List For Button, JavaScript, Jquery

The above Div contains three Classes and its ID is DivID. For getting the list of all classes into an array, we can follow below shown code.

var list = document.getElementById('DivID'). className.split(/\s+/);


For getting a particular Class from the above list, we can follow below code.

var list = document.getElementById('DivID'). className.split(/\s+/);
for (var i = 0; i < list.length; i++) {

         if (list[i] === 'Class Name') {
                  // You Code Here....
         }
}



That's only, by using above code we can Get The Class List For Element With JavaScript.