I do not want to select a hidden element. How can i do this?

I am using jQuery Plugin which uses the following line

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

He selects some element.

He also selects the hidden element, how can I achieve this without providing any class to the hidden element?

And it should work in IE.

+4
source share
3 answers

You can use the not () method for the array returned by the selector.

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

Filters hidden elements from the array returned by the selector.

+2
source

took me for a minute but realized this is jsfiddle example

sorry it didn’t save.

EDIT now without 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 jQuery

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

The warning should say “surprise” because the hidden element with the “bar” is not selected

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

Will also not display hidden items.

0
source

Source: https://habr.com/ru/post/1346041/


All Articles