Paul Dessert
Paul Dessert

Reputation: 6389

using .hasClass to target multiple classes

I'm using the following code to see if a form does not contain either class. It works fine if I only look for one, but if I add multiple classes to the if statement, it seems to bypass them.

if (!form.hasClass('no-ajax') || !form.hasClass('register-step')) {

HTML:

<form id="basic-info-form" class="register-step form efocus" method="post" action="form_process.php?source=newUser">

What am I doing wrong?

Upvotes: 0

Views: 157

Answers (2)

Dhinakaran
Dhinakaran

Reputation: 1

can you try like

var className = $('.myclass').attr('class');
 if(className.indexOf('myclasscheck') > = 0)

Upvotes: 0

JanR
JanR

Reputation: 6132

The problem is with your if statement. You are saying if the form does NOT have class no-ajax OR has class register-step. So if any of the conditions is true it will go into your if-statement.

you want to make sure it has neither class so it should be && instead of ||

Upvotes: 5

Related Questions