Hi,

I am a jQuery beginner. I am working on an application for which I
need to create DOM elements on the fly. Previously I was using
document.createElement() and document.createTextNode() but that's not
concise and looks odd along with jQuery code.

So I wrote a tiny 3 line plugin jquery.new.js. It's more of a hit and
trial outcome.

jQuery.new = function(element) {
        return $(document.createElement(element));
}

I wrapped the new element that was created with the jQuery object so I
can chain functions. For example:
var inputBox = $.new("input").attr("type", "text").attr("id",
"someText");

Is there a better way to do this? Or does jQuery already have this
functionality inbuilt?

Reply via email to