0

Possible Duplicate:
How to get a DOM Element from a JQuery Selector

I know using normal javascript i can do

formitem.validity.valid

or

formitem.checkValidity();

How do i use Jquery to call these functions? Below im using a custom attribute selector to get my element but cant seem to use it like below...

$('[data-dependID=pobText]').validity.valid

or

$('[data-dependID=pobText]').formitem.checkValidity();

Simple but how do i do this?

Community
  • 1
  • 1
Lemex
  • 3,772
  • 14
  • 53
  • 87

4 Answers4

1

Use Get,

i.e.

$('[data-dependID=pobText]').get(0).formitem.checkValidity();
Gavin
  • 6,284
  • 5
  • 30
  • 38
1

You need to get DOM Node for that:

$('[data-dependID=pobText]').get(0).validity.valid;
$('[data-dependID=pobText]').get(0).formitem.checkValidity();
antyrat
  • 27,479
  • 9
  • 75
  • 76
1

Use .get(n) to get the nth element as a DOM object, or just [n]

$('selector').get(n).foo

or

$('selector')[n].foo
Alnitak
  • 334,560
  • 70
  • 407
  • 495
1

jQuery calls to the DOM return an array-like object and so you can access the DOM elements in the "array" by an index. The get() method does the same thing, only that it encapsulates this in a function call (which is an overhead).

Better use the index instead:

$('[data-dependID=pobText]')[n].validity.valid;
$('[data-dependID=pobText]')[n].checkValidity();
Joseph
  • 117,725
  • 30
  • 181
  • 234