1

I have written a jQuery plugin as a form element that I want to reuse throughout mysite.

(function ( $ ) {
    $.fn.create = function() {
        var form = '<div id="form" class="container">';
        form += '<div>User Login</div>';
        form += '<form action="/create" method="post">';
        form += '<input type="text" name="name" placeholder="name">';
        form += '<input type="email" name="email" placeholder="email">';
        form += '<button type="submit">Login</button>';
        form += '</form>';
        form += '</div>';
        return this.append(form);
    };
}( jQuery ));

In HTML view,

<div id="#newForm"></div>

<script>
$(document).ready(function(){
    $("#newForm").create(); 
});
</script>

However, the form does not get rendered onto #newForm

guest
  • 2,185
  • 3
  • 23
  • 46

1 Answers1

6

You have an # in the id of the target div, remove the prefixed # and it should be fine

<div id="newForm"></div>

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531