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.
$(this).after( $("<div></div>").addClass(myClass) );
maybe something like:
var myClass = "thisIsMyClass";
var div = $("<div></div>").addClass(myClass);
$(this).after(div);
using the & didnt work because this is not vb, string concatenation is done with the +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With