AirWick219
AirWick219

Reputation: 944

jquery append a class without html markup rails

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

Answers (1)

MrYoshiji
MrYoshiji

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:

Upvotes: 1

Related Questions