IE , SCRIPT and innerHTML

Q

_q_u_a_m_i_s's

Hy,
Let`s suppose the following example:

<div id="parent">
<div id="child">
dfsfdg dsfg
</div>
<script type="text/javascript">
alert('a');
</script>
</div>


by using alert($('parent').innerHTML) in FF i can see the exact tags
as written.
When using the same alert in IE, i cannot see the contents of
<script></script>.. it shows me an empty tag.

Why does IE shows me an empty tag? i need to see the contents of that
tag, and have no ideea how.
Anyone know a solution to access the contents of the script tag in IE?

$('id') is shorthand to document.getElementById('id') for those who
never used prototype:)
 
Q

_q_u_a_m_i_s's

_q_u_a_m_i_s's said the following on 1/17/2008 9:46 AM:





Because something in Prototype is screwing it up. Or, something else in
the way you are trying to alert it.

<button
onclick="alert(document.getElementById('parent').innerHTML)">Test</button>

In IE7 gives me the script block contents.


Stop using prototype and access it directly, you will get the script
block contents.

I am curious why you need the text though. I have an idea about why but
am curious before I go any further with it.


<quote>
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <[email protected]>
</quote>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


Thanks for the answer, seems like i as wrong, it`s not the $()
function( or the getElementById)... it was cloneNode.. but i`ts still
not fixed:(
Let`s start with a little background:
I`m trying to make "cloneFactory" class in js. I need pretty often to
be able to add/delete rows in forms . these forms generally contain a
table, and i need to be able to duplicare different TR`s
Before trying to make this class i was using AJAX(to add the new row,
with new INPUT names and id`s) or weird js hacks, generally made
specific for that type of form row.

Now i want to make a "template" element, in this case a TR, which
contains element id`s and names in a specific form.
Example:
the template: <TR id="template_.index."><TD>[... inputs and texts...],/
TD></TR>

in js i do a
template=new CloneFactory('template_.index.',{'index':{start:5,
type:'int'}});
[....]
and then put a button in the page with onClick="template.clone()"

when creating the CloneFactory, it will remove the element from the
DOM, and keep it in memory (so it will not get submited by mistake).

the template.clone will call cloneNode, and parse the cloned element
from memory, and where it sees elements with tags in the form of
".tag." it will try to make the replace (For the above example, the
first call to clone will generate a <TR id="template_5"><TD>[...
inputs and texts...],/TD></TR> this tag will be automatically appended
to the DOM...
I need the script tags, so that i can create different field
validators for the inputs in that row

The problem with IE is that when calling cloneNode, it removes the
content of the <script> tags, and so the inputs will never get
validated.
It work perfectly in FF, but sucks in IE.

I belive i`ll have to change the node-parsing process to a simple
String.replace on the entire innerHtml of the original element... but
i`d prefer parsing each tag separatelly... String.replace can make
stupid replacements if used on a element wich actually contains a
textnode with the ".index." string in it (i`d like to avoid this if
its possible)
 

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

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top