Sadikhasan
Sadikhasan

Reputation: 18601

How to select Hidden Field?

I want to select field with following condition

  1. Id start with Product

    OR

  2. Id start with Product and Hidden field

My following code will only satisfy first condition I also want to satisfy 2nd condition. How is possible?

$("input[id^=Product]").each(function(){
        alert($(this).attr("id"));
});

Thanks for help.

Upvotes: 1

Views: 122

Answers (2)

Roko C. Buljan
Roko C. Buljan

Reputation: 206689

$('input[id^=Product]:hidden')

http://api.jquery.com/hidden-selector/
http://api.jquery.com/attribute-starts-with-selector/

If you really want an OR in the means target both with idStartsWith and idStartsWith+it'sHidden do like:

$('input[id^=Product], input[id^=Product]:hidden')

Upvotes: 2

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28523

Try this : You can use multiple attribute selector for input hidden type, put [type='hidden'] in selector

$("input[type='hidden'][id^=Product]").each(function(){
        alert($(this).attr("id"));
});

EDIT - As OP want to satisfy both condition. You can use comma separated selectors for this. Put your earlier selector with comma separated above selector. See code below -

$("input[id^=Product],input[type='hidden'][id^=Product]").each(function(){
            alert($(this).attr("id"));
   });

Upvotes: 2

Related Questions