avoid innerHTML parsing

S

Sergey Batishchev

I need to create element with some content inside. This may be any
HTML stuff - tags, text. I do next

Set newelem = doc.createElement("span")
newelem.innerHTML = "<a href=""test\test.htm"">1st</a>"

(code above is written in VB, but it does not matter)

but in saved HTML I have anchor with absolute path
<a href="file:///c:/test/test.htm">1st</a>

All I want is avoiding internal parsing of innerHTML. I found, that I
can
set anchor.href directly and it will not be parsed. But I need to
parse string with element and find "href" substring. This seem to be a
buggy way.
I prefer to do it with no workarounds, with some simple and bugs-free
way.
Is there any chance for that?
 
M

Martin Honnen

Sergey said:
I need to create element with some content inside. This may be any
HTML stuff - tags, text. I do next

Set newelem = doc.createElement("span")
newelem.innerHTML = "<a href=""test\test.htm"">1st</a>"

(code above is written in VB, but it does not matter)

but in saved HTML I have anchor with absolute path
<a href="file:///c:/test/test.htm">1st</a>

All I want is avoiding internal parsing of innerHTML. I found, that I
can
set anchor.href directly and it will not be parsed. But I need to
parse string with element and find "href" substring. This seem to be a
buggy way.
I prefer to do it with no workarounds, with some simple and bugs-free
way.
Is there any chance for that?

Try
var link = document.createElement('a');
a.href = 'test/test.html';
span.appendChild(a)
I don't see any reason to mix createElement with innerHTML assignment
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top