How to select specific div or Form which does not have specific class?


I want to select an HTML element (form) which does not have a specific class ('Ajax_Stop'), so that I can implement a jQuery function on that, basically when submitting a form I want to check if a form or div doesn't have that specific class using jQuery-javascript, & run a function if it doesn't have that CSS class.

How to do it using jQuery or javascript?


Asked by:- bhanu
1
: 2617 At:- 10/31/2017 12:13:33 PM
jQuery javascript select if not have specific class







3 Answers
profileImage Answered by:- neena

You can use jQuery's :not() function,suppose you want form or div which does not have class .Ajax then your jQuery code will be

$("form:not(.Ajax)").on('submit',function(){
//do soemthing
});

that's it

3
At:- 11/1/2017 7:47:40 AM


profileImage Answered by:- jaiprakash

jQuery has the .hasClass() function that returns true if any element has that specified class, so if it doesn't have, it will return false, and you can use it like

if (!$("form#FormId").hasClass("Ajax")) {
    //something here
}

So this will also work for you, and above answer by @neena is another method

1
At:- 11/2/2017 4:04:19 PM


profileImage Answered by:- pika

You can also use jQuery method .not()

$('form').not('.Ajax');

here is the short description of the jQuery selectors:

  • [attribute]
    Matches elements that have the specified attribute.
  • [attribute=value]
    Matches elements that have the specified attribute with a certain value.
  • [attribute!=value]
    Matches elements that either don't have the specified attribute or do have the specified attribute but not with a certain value.
1
At:- 11/15/2017 7:50:33 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use