I have a variable and use it for creating an HTML element with a class attribute:
var my_class="my_class";
$(this).after("<div class="+my_class+"></div>");
I get <div class="my_class"></div> as expected, but when adding a variable with space in it:
var my_class="my_class id";
$(this).after("<div class="+my_class+"></div>");
I get <div class="my_class" id></div> instead of <div class="my_class id"></div>. How can I change that?
$(this).after($("<div></div>").attr('class', my_class));"<div class='"+my_class+"'></div>"or a template literal:`<div class="${my_class}"></div>`instead.const $div = $('<div>');thendiv.addClass('my_class').addClass('id');(or both at once) then$(this).after($div);$("<div/>", { "class": "my_class id" })