Alex Rivera | Logout

Can jQuery create an element by a selector?

Asked 2010-08-19T04:05:33.437
10

Normally I would create an element in jQuery like this $('<div id="errors" class="red"></div>')

Can I create an element given a selector using something like $.create("div#errors.red")? Where that would return a jQuery object representing a div with the id of errors and the class of red?

Edit
Report

1 Answer

0

I dont think you can do that, the closer thing i know is that you can do

var newdiv = $.DIV({ className: "red", id: "errors"});

the div is created and you can append events and stuff directly to the variable

using this plugin http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype

answered 2010-08-19T04:15:10.830

Your Answer