When I am trying to do this:
var element_current_classes=($("#form_div :textarea").attr('class'));
or this:
var element_current_classes=($("#form_div :select").attr('class'));
I am getting this error - Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: textarea
It works only with 'input' and button
What I am trying to do is to find elements inside the form by their tags
Any ideas?
When I am trying to do this:
var element_current_classes=($("#form_div :textarea").attr('class'));
or this:
var element_current_classes=($("#form_div :select").attr('class'));
I am getting this error - Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: textarea
It works only with 'input' and button
What I am trying to do is to find elements inside the form by their tags
Any ideas?
Share Improve this question edited Sep 18, 2013 at 13:16 Chad Ferguson 3,0875 gold badges37 silver badges42 bronze badges asked Sep 18, 2013 at 12:58 David MunsaDavid Munsa 8931 gold badge17 silver badges33 bronze badges 2- Please read this w3/TR/CSS2/selector.html#pattern-matching – rafaelcastrocouto Commented Sep 18, 2013 at 13:01
- you can find list of additional selectors in sizzle (jq selector engine), there is no such selectors: github./jquery/sizzle/wiki/Sizzle-Documentation – A. Wolff Commented Sep 18, 2013 at 13:03
5 Answers
Reset to default 5There is no selector called :textarea
or :select
- you can use element selector to select the textarea or select element
$("#form_div textarea").attr('class')
$("#form_div select").attr('class')
The :input pseudo selector used to select multiple kinds of input elements like input, select, textarea etc
Correct way to select an html element is
var element_current_classes=($("#form_div textarea").attr('class'));
var element_current_classes=($("#form_div select").attr('class'));
Note: In jQuery for html tags and form elements we use name of the tag
$('div').hide(); // this code will hide all divs
Where as :
is a selector that is use to get a specific tag or element
$('div:last').hide(); // this code will hide only last div
var element_current_classes = $("#form_div select").attr('class');
you don't need :
selector to get textarea or select . just use element selector.
try this
var element_current_classes=$("#form_div select").attr('class'); //select
var element_current_classes=$("#form_div textarea").attr('class'); //textarea
You are confusing selectors like :input
with HTML tag names, like teaxtarea
.
$("#form_div textarea");
Will look for HTML tags <textarea>
within elements with the ID HTML attribute id="form_div"
.
Whereas:
$("#form_div :input");
Will look for all input tags, such as <textarea>
, <input>
, <select>
and <button>
, within the element with `id="form_div".
Selectors (starting with :
) are jQuery specific. See:
http://api.jquery./category/selectors/