QueueHammer
QueueHammer

Reputation: 10824

Jquery, Selector syntaxt help, get all text fileds

I have a selector that works like this:

$('#container textarea, #container :text');

However this does not work.

$('#container').filter('textarea, :text');

Though, I have read that the filter command is the same as:

var context = $('#container');
$('textarea, :text', context);

Which does work

How can i get the the selector to work in the second expression?

Upvotes: 0

Views: 67

Answers (1)

Felix Kling
Felix Kling

Reputation: 816452

Wherever you read this, it is wrong.

var context = $('#container');
$('textarea, :text', context);

is equivalent to using .find()

$('#container').find('textarea, :text');

filter filters the current selected elements, it does not search its descendants. So your second expression would return the element selected by $('#container') if it is a textarea or some text input field.

To make use of native functions in recent browsers you should use input[type="text"] instead of jQuery's :text.

Upvotes: 1

Related Questions