6

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.

1

7 Answers 7

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

Where value is the value of the element you want to delete. :)

Sign up to request clarification or add additional context in comments.

Comments

7

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.

Comments

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

http://jsfiddle.net/rZczZ/

Comments

0

Use the replaceWith() function.

http://api.jquery.com/replaceWith/

Comments

0

I assume you mean an input box value?

In which case why not...

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

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

That'll clear the value of the text box.

Comments

0

You can simply use this code to remove particular inputs.

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

Comments

0

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>

1 Comment

input elements have no content though, so :contains does not work on them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.