Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a class in javascript exists

Tags:

javascript

I am defining a class in javascript using this...

// file_a.js function class_a() {     this.prop1 = null;     this.prop2 = null; }  // file_b.js var obj = new class_a; // I need to check here if class_a exists 

How can I do this?

Regards

like image 301
vikmalhotra Avatar asked Nov 30 '10 13:11

vikmalhotra


People also ask

How do I know if a CSS class is applied?

In vanilla JavaScript, you can use the contains() method provided by the classList object to check if any element contains a specific CSS class. This method returns true if the class exists, otherwise false .

How do you check whether the class is present or not in jQuery?

The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".

What does classList do in JavaScript?

JavaScript classList is a DOM property of JavaScript that allows for styling the CSS (Cascading Style Sheet) classes of an element. JavaScript classList is a read-only property that returns the names of the CSS classes.


1 Answers

if (typeof class_a === 'function') 
like image 143
Quentin Avatar answered Sep 17 '22 12:09

Quentin