I have a string with HTML from the website like:
\n
<div>
\t<div>
...
\t</div>
</div>
If I construct a jquery from this by:
$(tmpl) // like $("\n<div>")
It will give me error saying "unrecognized expression:<div> <div> </div></div>"
.
I tried using $(tmpl.replace(/[\t\r\n]/,""))
. It works but does not seem natural to me.
I also tried using $('body').append(tmpl)
; it does not require a replace
but I want to change the attr/styles/data before I attach it to DOM. If I attach it first, I will need to select it again.
Is there any way to create a jquery object from this type of HTML snippets without replace
and before attaching it to DOM?