jquery .addType()

Vince picture Vince · Apr 11, 2013 · Viewed 10.8k times · Source

Is there a .addType() function for jquery? I know there's a .addClass() to add the class, but I'm appending an input element to a div using the shorthand way and was wondering if there is a .addType() to add the type to the input area i.e text, password, submit.

$(document).ready(function(){
  $("#newnum").click(function(){
    $("#equation").append(
      $("<input/>")
    );
  });
});

Answer

Schleis picture Schleis · Apr 11, 2013

You could just use the shorthand

$('<input type="text">');

There is also the attr() which would let you do the same thing

$('<input>').attr('type', 'text');