It's already built in. For your example:

  var inputBox = $('<input>').attr("type", "text").attr("id", "someText");

Or even:

  var inputBox = $('<input type="text" id="someText">');

Karl Rudd

On 8/17/07, Anurag <[EMAIL PROTECTED]> wrote:
>
> 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