Gaurav
Gaurav

Reputation: 28755

I don't want to select hidden element, How can I do that?

I am using a JQuery Plugin, which uses following line

var inputSelector = 'input[class]:not(:button|:submit|:reset), textarea[class], select[class]';

It select some element.

It also selects the hidden element, how can I achieve that without giving any class to hidden element?

And It must work in IE.

Upvotes: 4

Views: 2257

Answers (3)

mcgrailm
mcgrailm

Reputation: 17640

took me a minute but figured it out jsfiddle example

sorry it didn't save right

EDIT now with no class

here is the html

<input type="text" name="foo" />
<input type="hidden" name="hidden" id="bar" value="surprise" />
<input type="submit" name="submit" />

here is the jQuery

var inputSelector = 'input:not(:button, :submit, :reset,:hidden), textarea, select';
$(inputSelector).val('foobar');
var bc = $('#bar').val();
alert(bc);

The alert should say "surprise" because the hidden element with id "bar" is not selected

Upvotes: 1

Daniel Dyson
Daniel Dyson

Reputation: 13230

You could use the not() method on the array returned by the selector.

var inputSelector = 'input[class]:not(:button|:submit|:reset), textarea[class], select[class]';
var controls = $(inputSelector).not('[type="hidden"]');

This filters the hidden elements out of the array returned by the selector.

Upvotes: 2

Glen Solsberry
Glen Solsberry

Reputation: 12320

var inputSelector = 'input[class]:not(:button|:submit|:reset|:hidden), textarea[class], select[class]';

Will not select hidden elements as well.

Upvotes: 0

Related Questions