Aaron
Aaron

Reputation: 10430

I'm having problems checking if class exists with jQuery

The blow script works but is also outputting a "type e" error in jquery...

I've been looking at this for about 20mins now and am failing to see the problem.

if ($('input[type="submit"]').hasClass('.grey-button')) {
        $(this).wrap('<span class="button grey-button"></span>');
    } else {
        $(this).wrap('<span class="button"></span>');
    }

What am i mssing ?

Upvotes: 0

Views: 31

Answers (3)

Chandan Sarma
Chandan Sarma

Reputation: 308

To check the class we doesn't not need . with the selector. changed it as below

.hasClass('grey-button')

Upvotes: 0

Tamil Selvan C
Tamil Selvan C

Reputation: 20199

Don't need to use .classname in hasClass(). just call with classname without dot eg hasClass('classname');

just use

$('input[type="submit"]').hasClass('grey-button')

Upvotes: 2

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

Checking with hasClass doesn't require to pass selector (the dot):

.hasClass('grey-button')//just use class name

Upvotes: 1

Related Questions