title: Javascript function parameter into jQuery or HTML tags
body: <p>This is my original code to create an input field:</p>
  
  <pre><code>$('#dynamicForm').append('&lt;li id="pdport"&gt;&lt;/li&gt;');
  $('#pdport').append("&lt;label for='sport'&gt;Destination port&lt;/label&gt;")
  $('&lt;input&gt;').attr({type: 'text', id: 'dport', name: 'dport'}).appendTo('#pdport');
  $('#pdport').append("&lt;span&gt;Enter the destination port here (0-65535)&lt;/span&gt;");
  </code></pre>
  
  <p>Instead of doing this code over and over I'm trying to create a function for it</p>
  
  <pre><code>function createInputfield(mainID, childID, labelFor, labelText, spanText){
      $(mainID).append('&lt;li id=childID&gt;&lt;/li&gt;');
      $(childID).append("&lt;label for=labelFor&gt;labelText&lt;/label&gt;")
      $('&lt;input&gt;').attr({type: 'text', id: labelFor, name: labelFor}).appendTo(childID);
      $(childID).append("&lt;span&gt;spanText&lt;/span&gt;");
  }
  </code></pre>
  
  <p>and than calling to function with </p>
  
  <pre><code>createInputfield("#dynamicForm", "#psport", "sport", "Source port", "Enter the source port here (0-65535)");
  </code></pre>
  
  <p>this way I can create a lot of dynamic input fields without copy/pasting a lot of the same code.</p>
  
  <p>The problem is that this doesn't work, I always get syntax errors, like you can't append on mainID and others. I tried a lot of different ways to accomplish this like with quotes, with single quotes, without.. But nothing seems to work. </p>