Append DIV and immediately add class in jQuery

jquery

Solution

$(this).after( $("<div></div>").addClass(myClass) );

Problem

What I'm trying to accomplish: I want to add a DIV after an existing DIV and assign it a specific class. I started with this: ``` var myClass = "thisIsMyClass"; $(this).after("<div></div>").addClass(myClass) ``` The problem with that is that myClass gets added to $(this) rather than the newly created DIV. So I gave this a try: ``` var myClass = "thisIsMyClass"; $(this).after("<div class='" & thisIsMyClass & "'></div>") ``` But jQuery doesn't like that either. I can do this, however: ``` $(this).after("<div class='thisIsMyClass'></div>") ``` jQuery is OK with that syntax. Of course, I lose the ability to pass it in as a variable. I'm guessing I'm doing something fairly obviously wrong. But I'm stumped as to what that is.

Original source