What is wrong with this jquery expression?
I am trying to select all my textboxes with...
$("input[@type=text]")
From the jquery docs it seems this should be valid syntax.
Down the page at http://docs.jquery.com/DOM/Traversing开发者_开发技巧/Selectors there is an example given...
$("input[@type=radio][@checked]")
... which is very similar to what my expression does. When I 'watch' my expression with FireBug I get a
Syntax error, unrecognized expression: [@type='text']
error.
I have tried ...
$("input[@type='text']")
as well to no avail. I appreciate any tips!
The API documentation you're looking at is old (probably based on XPath selectors). You want to look at the attribute-equals selector. There's also other attribute selectors (contains, starts with, etc) if you're interested.
$("input[type='text']")
should work for you
Example: http://jsfiddle.net/jonathon/hCRkW/
Try:
$('input:text')
And:
$('input:radio')
The @ selectors were deprecated in jQuery 1.2, and I believe disappeared in 1.3.
Try this: $('input[type="text"]')
Try $('input[type=text]')
.
I think in older version of jquery you needed the @ sign before the attribute name. Newer version don't want it.
See http://api.jquery.com/attribute-equals-selector/
精彩评论