1

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

AirWick219
  • 894
  • 8
  • 27

1 Answers1

1

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:

Community
  • 1
  • 1
MrYoshiji
  • 54,334
  • 13
  • 124
  • 117