dooberry Posted June 1, 2006 Share Posted June 1, 2006 Guys,I'm having real trouble here and I've resorted to spamming a little (my profuse apologies!).Can anyone tell me how to dynamically write content to a div element.I've tried using the InnerHTML property, but that cleans out functional elements such as script and style.It is not possible to change the outerHTML property dynamically because Explorer doesn't allow it.I've had this problem before with table cells and frames are not suitable for the project.I thought there might be something within the div element like div.body.document, but I can't find anything.Please help!Dooberry Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 1, 2006 Share Posted June 1, 2006 There is no such thing as a body inside a div, what are you talking a bout ? Link to comment Share on other sites More sharing options...
dooberry Posted June 1, 2006 Author Share Posted June 1, 2006 Yeah, you're right and that is the problem.What I'm trying to do is find a property (Javascript type property) within the div element that has a write() method.If I can do this, then I can change the content dynamically and not have things like script and styles stripped out of the html inside the div element.what I am looking to be able to do is something like: document.getElementById("displaydiv").whateverthecontentobjectis.write(myxmlddocument.transformNode(thexsltransformdocument)) I know that this can't be done using the innerHTML property because I've tried it and it will only add HTML elements, not style or script elements.The reason I have to do it this way is because the styles are allocated dynamically by the XSL sheets, and storing them in the main webpage is not an option.If you know of such a property then that would be great.Dooberry sits rocking in the corner.EDIT: PS My name's Dan too! Link to comment Share on other sites More sharing options...
dooberry Posted June 1, 2006 Author Share Posted June 1, 2006 Ok,I have an idea using an iframe.I can write to the content of the iframe, but is there a way of calling script functions which are outside of the document in the iframe? If this works, then the same should be able to be done with frames.I need to be able to manipulate a global variable which stays as the content of the iframe changes any ideas? Link to comment Share on other sites More sharing options...
aspnetguy Posted June 1, 2006 Share Posted June 1, 2006 use this document.getElementById('divID').innerHTML = 'what ever you want to put'; Link to comment Share on other sites More sharing options...
scott100 Posted June 1, 2006 Share Posted June 1, 2006 Can anyone tell me how to dynamically write content to a div element.I've tried using the InnerHTML property, but that cleans out functional elements such as script and style.Well could you not just write a div within a div? This would allow you to add style/script like so:<html><script type="text/javascript">function change(){document.getElementById('myDiv').innerHTML='<div style="color:red" onclick="alert(\'Hello\')">Hello, click me</div>';}</script><body onload="change()"><div id="myDiv"></div></body></html> Link to comment Share on other sites More sharing options...
dooberry Posted June 1, 2006 Author Share Posted June 1, 2006 This might work, but I think I know another way round it.The innerHTML property is still allocating the class attribute, so I can move the class definition out of the XSL sheet and into the 'home page'.This should allow the home page to understand the style required when the class is allocated.edit: It worked - I was stuck in my box again!Thanks for all your help guys - sorry to be a nuisance.Also if anyone is reading this post looking to change the text content of a div dynamically you can do it this way: document.getElementById('divelementid').removeChild(document.getElementById('divelementid').childNodes[0])document.getElementById('divelementid').appendChild(document.createTextNode(textcontent)) Well shizzle my nizzle! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now