Guys how can i remove an input with a specific value using jquery?
I know i should user .remove() but i don't know how to find the specific input.
Loop into the <input> fields then match each values, if match, then remove it:
$(document).ready(function() {
$('input[type=text]').each(function() {
if ($(this).val() === "foo") {
$(this).remove();
}
});
});
Demo here jsFiddle.
$(function(){
$("input[type='button']").click(function(){
$("input[type='text']").each(function(){
var $this = $(this);
if ($this.val() == "x"){
$this.remove();
}
});
});
});
Removes all inputs that contain "hello" from the DOM.
<!DOCTYPE html>
<html>
<head>
<style>p { background:yellow; margin:6px 0; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p class="hello">Hello</p>
how are
<p>you?</p>
<button>Call remove(":contains('Hello')") on paragraphs</button>
<script>
$("button").click(function () {
$("input[type='text']").each(function(){
if($(this).val().toLowerCase().indexOf('hello')!=-1)
$(this).remove();
})
});
</script>
</body>
</html>
input elements have no content though, so :contains does not work on them.