开发者

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

I am using a J开发者_运维问答Query 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.


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.


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


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

Will not select hidden elements as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜