SyntaxFix
Write A Post
Hire A Developer
Questions
Much more expressive way,
jQuery('<div/>', { "id": 'foo', "name": 'mainDiv', "class": 'wrapper', "click": function() { jQuery(this).toggleClass("test"); }}).appendTo('selector');
Reference: Docs