Not clear what the pasted code is doing, some of the HTML tag could be sanitized when you make the post. I'm guessing, the code is trying to append a div element on top of the h6 element? and the div will have a class? Anyway, the below example and reading materials should help.
Here is an example: CP_JS_insertB4 - JSFiddle
Here is more reading to get you started: HTML DOM insertBefore Method