How to find/remove input element in form by value ?
Asked
Active
Viewed 417 times
0
-
1Do you want to remove all input elements that contain the value, or just the first one? Are the inputs we're talking about text boxes, radio buttons, drop down lists? Your question needs a lot of clarification before it can be answered. – Kiley Naro Sep 24 '11 at 21:17
2 Answers
2
You can use filter
to cover all the bases:
var matches = $('input').filter(function() { return this.value == 'what you want' });
matches.remove(); // If you want to remove them of course.
An attribute selector only sees things that have the value
attribute set in the DOM so that won't see an <input>
that has been updated with a val(x)
call, using a filter
will see things that have been updated with .val(x)
.
For example: http://jsfiddle.net/ambiguous/RVWu6/

mu is too short
- 426,620
- 70
- 833
- 800
-
That's the second time this particular nuance has got me... `:s` – Jared Farrish Sep 24 '11 at 21:30
0
Making an initial guess at what you're trying to accomplish, you should probably take a look at this question:
How can I select a hidden field by value?
The suggestion there is $('input[value="Whatever"]')
From there you can use the jQuery remove
function: http://api.jquery.com/remove/

Community
- 1
- 1

Kiley Naro
- 1,749
- 1
- 14
- 20
-
1This selector doesn't work for `value`, unless the attribute of an element is explicitly set (in the HTML source, of by JavaScript). – Rob W Sep 24 '11 at 21:22