I have a very simple piece of jQuery code (jQuery 1.7.1). Though the error below shows up, and the code isn't executed.
Uncaught HierarchyRequestError: A Node was inserted somewhere it doesn't belong.
The code that causes this error is as follows:
counter = 0;
jQuery('h3').each(function(){
counter += 1;
div = '<div class="' + counter + '"></div>';
jQuery(this).after(div);
jQuery(this).nextUntil('h3').appendTo('div.' + counter);
});
For some reason, the jQuery(this).after(div);
causes a problem. It has something to do with the class I am adding to the div (specifically the class, not the variable I set as class). At first I used append instead of after, but that didn't give the desired effect. However, append didn't give an error.
Can anyone clarify why I am not allowed to add a class in the after function, and if possible, give me a good alternative to tackle this problem?