Handy addClass use in .append

Handy addClass use in .append

  1. $('body').append('<div id="mydiv"></div>).addClass('newClass');

addClass can be used to add a class to a selector. Take the above example. If the class is added to 'mydiv' instead, not body, this could be handy than writing the two lines:
  1. $('body').append('<div id="mydiv"></div>);
  2. $('#mydiv').addClass('newClass');