PrateekSaxena Posted March 10, 2007 Share Posted March 10, 2007 How do I get and edit the whole documents innerHTML??I mean should I enclose everything that is in the BODY into a DIV or is there a way to edit the documents HTML??I want to add a new DIV to the body, how do I do that?? Link to comment Share on other sites More sharing options...
vytas Posted March 10, 2007 Share Posted March 10, 2007 You could first make the div without nothing in it like <div id="text1"> </div> And with JavaScript add something in it like <script type="text/javascript">function makeTxt(){document.getElementById('text1').innerHTML="Your text here";}</script> OR <script type="text/javascript">function newDiv(){var page = document.body.innerHTML;document.body.innerHTML=page+" <div id='text1'> Your text here</div>";}</script> Havn't tested the code's yet , reply if something is wrong. Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 10, 2007 Author Share Posted March 10, 2007 I already know that I can do it in this way, and I said so in my initial message. I want to know some other way to do the same!! Link to comment Share on other sites More sharing options...
vytas Posted March 10, 2007 Share Posted March 10, 2007 Hmm , i dunno then. Link to comment Share on other sites More sharing options...
Kevin M Posted March 10, 2007 Share Posted March 10, 2007 You could change the page content using AJAX if that's what you mean?So if a user clicks a link, then it's sort of like a frame, except not using frames. Does this make sense? I'd read the AJAX tutorial at W3Schools if you haven't already. Link to comment Share on other sites More sharing options...
aspnetguy Posted March 10, 2007 Share Posted March 10, 2007 you can use the DOM.if you want to add a new div directly to the body you can do this. var newDiv = document.createElement("div");newDiv.id = "newDiv";newDiv.appendChild(document.createTextNode("You text here"));document.body.appendChild(newDiv); Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 10, 2007 Author Share Posted March 10, 2007 document.createElement("div");That is what is I was looking for, thanks!!EDIT: by the way aspnetguy, I wanted to tel you that I have posted the code of hanman and nrvtac4 on the so many langs thing!! see it Link to comment Share on other sites More sharing options...
jesh Posted March 12, 2007 Share Posted March 12, 2007 For more info on the createElement, createTextNode, and appendChild methods, check out the XML DOM tutorial. Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 12, 2007 Author Share Posted March 12, 2007 Thanks! Quite suprisingly I was viewing the same tutorial right now!! Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 12, 2007 Author Share Posted March 12, 2007 var newDiv = document.createElement("div");newDiv.id = "jsConsole";var it = document.getElementById("jsConsole"); It get the error that it soes not have any properties when I set its height. Link to comment Share on other sites More sharing options...
jesh Posted March 12, 2007 Share Posted March 12, 2007 This code works for me in both Firefox and IE: var newDiv = document.createElement("div");newDiv.id = "jsConsole";newDiv.style.height = "44px";newDiv.style.backgroundColor = "red"; You get the error when you try to set the height? Or are you getting the error when you try to append the element to the document? Link to comment Share on other sites More sharing options...
aspnetguy Posted March 12, 2007 Share Posted March 12, 2007 you have not appended the new element to the dom yet. Either add it ot he body or a wrapper of your choice. var newDiv = document.createElement("div");newDiv.id = "jsConsole";document.body.appendChild(newDiv);var it = document.getElementById("jsConsole"); Link to comment Share on other sites More sharing options...
jesh Posted March 12, 2007 Share Posted March 12, 2007 you have not appended the new element to the dom yet. Either add it ot he body or a wrapper of your choice.var newDiv = document.createElement("div");newDiv.id = "jsConsole";document.body.appendChild(newDiv);var it = document.getElementById("jsConsole"); Ahh, right you are, you still have to append the element to the document. But, just so you know, Prateek, there is no reason in doing the document.getElementById("jsConsole") at this point because you already have a reference to that element in "newDiv". Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 12, 2007 Author Share Posted March 12, 2007 But, just so you know, Prateek, there is no reason in doing the document.getElementById("jsConsole") at this point because you already have a reference to that element in "newDiv".ok got ithow come nonw of you have replied to the JS Console in the General Forum?? Link to comment Share on other sites More sharing options...
aspnetguy Posted March 12, 2007 Share Posted March 12, 2007 I haven't had time to test it out. Just a question from looking at the screenshot. How is this integrated with an actual script to debug? Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 12, 2007 Author Share Posted March 12, 2007 Allows you to log stuff and add watched for the time being. More feature coming soon. you can write thing like con= new myConsole("JS Maker Rel2");con.log("I was logged","info");var ans=42;con.addWatch("The Answer",ans); more stuff to come...need you guys feedback Link to comment Share on other sites More sharing options...
aspnetguy Posted March 12, 2007 Share Posted March 12, 2007 I'll check it out and use next time I am writing a JS app. Would be very handy to see outputs when debugging,etc. Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 13, 2007 Author Share Posted March 13, 2007 Ok...cool 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