Jquery remove input with x value

Guys, how can I remove an input with a specific value using jquery?

I know what the user should .remove(), but I do not know how to find a specific input.

+3
source share
7 answers

Loop into the fields <input>, then match all the values ​​if they match, and delete them:

$(document).ready(function() {
    $('input[type=text]').each(function() {
        if ($(this).val() === "foo") {
            $(this).remove();
        }
    });
});​

Demo here is jsFiddle .

+4
source
$("input[value='"+value+"']").remove();

Where valueis the valueitem you want to delete. :)

+10
source
​$(function(){
    $("input[type='button']").click(function(){
        $("input[type='text']").each(function(){
           var $this = $(this);
            if ($this.val() == "x"){
               $this.remove();
            }                
        });
    });        
});​

http://jsfiddle.net/rZczZ/

+1

, ?

...

<input id="textField" type="text" value="testValue" />

$("#textField").val("");

.

0

.

$(function(){
    $("input[type='button']").click(function(){
        $("input[value=x]").remove();
    });        
});
0
source

Removes all inputs containing hi 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>
0
source

All Articles