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,734
  • 14
  • 50
  • 87

4 Answers4

1

Use Get,

i.e.

$('[data-dependID=pobText]').get(0).formitem.checkValidity();
Gavin
  • 6,116
  • 5
  • 28
  • 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
  • 26,950
  • 9
  • 73
  • 75
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
  • 325,660
  • 70
  • 395
  • 481
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
  • 113,089
  • 28
  • 177
  • 225