Reputation: 944
Is there a cleaner way to append a class after a selector with out the html markup div ?
$('#apple').append($('<div></div>').addClass('icon-spinner'));
//something else other than '<div></div>' ???
Most of the example that I found has some sort of html markup but i believe there are cleaner ways
Upvotes: 1
Views: 85
Reputation: 54882
The best method to create a div element (performance and syntax):
var div = $(document.createElement('div'));
div.addClass('icon-spinner');
$('#apple').append(div);
JSFiddle: http://jsfiddle.net/y68L3/2/
References:
What is the most efficient way to create HTML elements using jQuery?
Benchmark: http://jsperf.com/jquery-vs-createelement
Upvotes: 1