title: How to check if there exist an input with specific name attr using jQuery
body: <p>I need a function to add new input element dynamically using jQuery.</p>
  
  <p>It is something like this</p>
  
  <pre><code>function addInput(inputName) {
    $('&lt;input&gt;', {
      type: "hidden",
      name: "inputName"
    }).appendTo('#foo');
  }
  
  addInput('test');
  </code></pre>
  
  <p>and it works, It adds a new <code>&lt;input type="hidden" name="test"&gt;</code> to <code>#foo</code></p>
  
  <p>Problem appears when I want to make this function add input only if input with specified name does not exists in <code>DOM</code>.</p>
  
  <p>Here is my updated function</p>
  
  <pre><code>function addInput(inputName) {
    if (! $(input).attr('name','inputName') {
      $('&lt;input&gt;', {
        type: "hidden",
        name: "inputName"
      }).appendTo('#foo')
    }
  }
  
  addInput('test');
  </code></pre>
  
  <p>But insteed checking for <code>input</code> elements with the name <code>test</code> it sets name of all <code>input</code> elements to <code>test</code>.
  Is there any method to only test input name?</p>