/    Sign up×
Community /Pin to ProfileBookmark

JavaScript and Convert string to DocumentFragment

Hello,

I have variable type of string:

[CODE]var zmienna = “<div>Add</div>”;[/CODE]

I want convert this variable to DocumentFragment. I find this code:

[CODE]var tagString = “<div>Add</div>”;
var range = document.createRange();
var documentFragment = range.createContextualFragment(tagString);
var e = document.getElementById(“element”);
e.appendChild(documentFragment);[/CODE]

but this code work only in FireFox. How this code change, I want use this code in FireFox and IE and all browsers.


Grzegorz Wi&#347;niewski

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@grzeswisniewskiauthorJun 15.2009 — I create this code:

[CODE]var element = document.getElementById("component");

element.innerHTML = sender.responseText;


var scripts = element.getElementsByTagName("script");

if (scripts != null) {
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];

if (script.type == "text/javascript") {
eval(script.innerHTML);
}
}
}[/CODE]


but work only in FireFox. In IE 'scripts.length' = 0. Of course 'sender.responseText' return code:

[CODE]<script type="text/javascript">
alert("test");
</script>[/CODE]


How I can reload DOM Tree in IE?

--

Grzegorz Wi&#347;niewski
×

Success!

Help @grzeswisniewski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...