How would I check if a class name exists within the dom and create and if statement off that in pure JavaScript?
if(Check if a class name exists in the dom) {
document.getElementById('btnNxt').setAttribute('disabled', true);
}
How would I check if a class name exists within the dom and create and if statement off that in pure JavaScript?
if(Check if a class name exists in the dom) {
document.getElementById('btnNxt').setAttribute('disabled', true);
}
As written by gurvinder372 all you need to do is use "querySelector".
if(document.querySelector(".className"))
{
// do stuff
}
Similar to jQuery selectors, by targeting only the class you are instrested in, you can see if any DOM element has the class attached in the returned element. If no element is found by the selector, null is returned. Lookup Query Selector here for more info!