Roar
Roar

Reputation: 2167

HTML5 jQuery select all date fields 'input:date'

Is there a way to select all date inputs?
I have:

<input type="date" name="bday">

all i need it's just to select all inputs.
there are many selectors, but nothing like:

$('input:date')

this approach

 $("input[type='date']")

looks no good

What's the best practice?

Upvotes: 11

Views: 23348

Answers (2)

victor
victor

Reputation: 1676

If you want something cross browser, you should stick with:

$('input[type="date"]')

I don't think you can select all inputs of type date in a different way. If however you want to select all text fields you can go with

$(':text') 

or if you want all radios you can go with

$(':radio')

Upvotes: 30

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

Reputation: 33880

The cleanest way is to add a class "date" to all your input and select them with $('.yourClass').

If you can't add class, i don't see why $("input[type='date']") "look no good".

Maybe you want something like $('input').filter('[type=date]')?

Upvotes: 1

Related Questions