jqueryfunctionadd-type

jquery .addType()


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/>")
    );
  });
});

Solution

  • 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');