Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Can jQuery create an element by a selector?

4 like 0 dislike
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?
asked 1 year ago by Edward (33,730 points)

1 Answer

2 like 0 dislike
 
Best answer
You can try

$("<div id="errors" class="red"></div>").appendTo("body");
answered 1 year ago by BloggeR (179,550 points)

Related questions

6 like 0 dislike
0 answers
8 like 0 dislike
1 answer
9 like 0 dislike
1 answer
8 like 0 dislike
2 answers
asked 1 year ago by SeO (39,810 points)