Invalid target element for this operation / insertAdjacentHTML 
Author Message
 Invalid target element for this operation / insertAdjacentHTML

What is wrong with this.

HTML

<script type="text/javascript" id="s1">
<div id="d1"></div>

SCRIPT

// works fine
document.all('d1').insertAdjacentHTML('beforEnd','<div id="d2"></div>')

// Invalid target element for this operation
//document.all('s1') returns object to script block
document.all('s1').insertAdjacentHTML('BeforeEnd','function
test(){alert("Hej")}')

Why it is inposible to load innerHTML to script block?

Jacek

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 04:03:20 GMT  
 Invalid target element for this operation / insertAdjacentHTML
Use document.createElement("script"), assigne the appropriate properties (actual script code is assigned via the text property) and an appropriate appendChild to add it to the document.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> What is wrong with this.

> HTML

> <script type="text/javascript" id="s1">
> <div id="d1"></div>

> SCRIPT

> // works fine
> document.all('d1').insertAdjacentHTML('beforEnd','<div
> id="d2"></div>')

> // Invalid target element for this operation
> //document.all('s1') returns object to script block
> document.all('s1').insertAdjacentHTML('BeforeEnd','function
> test(){alert("Hej")}')

> Why it is inposible to load innerHTML to script block?

> Jacek

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 04:44:56 GMT  
 Invalid target element for this operation / insertAdjacentHTML
Do not work!
I was trying every thing.

var tmp = document.createElement('<script
type="text\/javascript"><\/script>')

// error
tmp.innerHTML = myHTML;
tmp.innerText = myText;

var tmp = document.all('js1')
var tmp2 = tmp.cloneNode(true)
tmp2.id='js2'
tmp2.innerHTML = myHTML

Jacek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 07:23:20 GMT  
 Invalid target element for this operation / insertAdjacentHTML
<html>
<head>
<title>
dynamic script addition
</title>
<script>
function addScript () {
   var script = document.createElement('script');
   script.defer = true;
   script.type = "text/javascript";
   script.text = 'alert("foobar")';
   document.getElementsByTagName('head')[0].appendChild(script);
Quote:
}

</script>
</head>
<body onload="addScript();">
foobar</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> Do not work!
> I was trying every thing.

> var tmp = document.createElement('<script
> type="text\/javascript"><\/script>')

> // error
> tmp.innerHTML = myHTML;
> tmp.innerText = myText;

> var tmp = document.all('js1')
> var tmp2 = tmp.cloneNode(true)
> tmp2.id='js2'
> tmp2.innerHTML = myHTML

> Jacek

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 07:38:21 GMT  
 Invalid target element for this operation / insertAdjacentHTML
Thenks.

It works.
You can see how on http://www.jaceknet.com/scdemo/adm/smmain.asp

MSDN help cose the problem.

text properti
Description

Retrieves the textual content of the block element as a string.

Syntax
object.text

Remarks

This property has read-only permission, meaning you can retrieve its
current value, but not change it.

Applies To

SCRIPT, TITLE

Jacek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 08:59:30 GMT  
 Invalid target element for this operation / insertAdjacentHTML
When you create elements dynamically with createElement, properties that are normally read only are writable (I presume) until they are appended to the document.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> Thenks.

> It works.
> You can see how on http://www.jaceknet.com/scdemo/adm/smmain.asp

> MSDN help cose the problem.

> text properti
> Description

> Retrieves the textual content of the block element as a string.

> Syntax
> object.text

> Remarks

> This property has read-only permission, meaning you can retrieve its
> current value, but not change it.

> Applies To

> SCRIPT, TITLE

> Jacek

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 10:20:14 GMT  
 Invalid target element for this operation / insertAdjacentHTML
They are writable after appending to the document.

document.all('js1').text = myScriptText

Jacek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 01 Oct 2004 17:03:28 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Invalid operation on closed object

2. write script into another frame with innerHTML/insertAdjacentHTML

3. insertAdjacentHTML and removeChild

4. insertAdjacentHTML Questions...

5. HELP: InsertAdjacentHTML Problem

6. insertadjacenthtml of object to trigger autodownload...

7. insertAdjacentHTML Method

8. insertAdjacentHTML

9. Cross Browser insertAdjacentHTML() ??

10. using asp var in "insertAdjacentHtml"

11. getting a spec element in multiple elements having same id att

12. Finding # of specific element in forms elements collection

 

 
Powered by phpBB® Forum Software