Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select a hidden field by value?

I have the following HTML generated by an ASP.NET repeater:

<table>   <tr>     <td><input type="hidden" name="ItemId" id="ItemId" value="3" /></td>     <td>Terry</td>     <td>Deleted</td>     <td>Low</td>     <td>Jun 21</td>    </tr>   <!-- rows repeat --> </table> 

How do I select a particular hidden field by value, so that I can then manipulate the columns next to it?

like image 685
flesh Avatar asked Jun 30 '09 20:06

flesh


People also ask

How do you assign a value to a hidden field?

In jQuery to set a hidden field value, we use . val() method. The jQuery . val() method is used to get or set the values of form elements such as input, select, textarea.

How do I access the input type hidden?

The <input type="hidden"> defines a hidden input field.


2 Answers

Using jQuery Selectors, you can target your element by a certain attribute matching the desired value:

$('input[value="Whatever"]'); 

This way you are targeting an input element, by the attribute value that is equal to the desired value.

EDIT 5/14/2013: According to an answer below, this no longer works as of jQuery 1.9.

like image 161
Michael Bray Avatar answered Oct 13 '22 20:10

Michael Bray


Note: Since jQuery 1.9 the input[value="banana"] selector is no longer valid, because 'value' of the input is technically not an attribute. You need to use the (far more difficult to read) .filter

E.g.

$("input").filter(function () {     return this.value === "banana"; }); 

See also: jQuery 1.9.1 property selector

like image 21
Glyn Jones Avatar answered Oct 13 '22 19:10

Glyn Jones