Jayababu
Jayababu

Reputation: 1621

use 'this' keyword along with css pseudo selectors

I want to use pseudo selectors along with this attribute. How can I use it.

$('input:valid').length

It will return 1 if its valid else 0 for invalid.

the same if I want to achieve using this how can I do that. something like this.

$('input').focusout(function(){
var flag=$('this:valid').length;
console.log(flag);
})

But its not working. Please guide me how to do this.

Upvotes: 0

Views: 67

Answers (2)

PeterKA
PeterKA

Reputation: 24638

Try this instead:

var flag=$(this).filter(':valid').length

REF: .filter() | jQuery API Documentation

Upvotes: 2

A. Wolff
A. Wolff

Reputation: 74420

You should use is():

var flag = $(this).is(':valid'); //returns boolean

Upvotes: 5

Related Questions