innerHTML solution for FireFox

Posted on 2006-04-10
Last Modified: 2008-02-01
In the IE6 I can use Javascript to get the innerHTML   ie       "something".innerHTML

But in Firefox nothing is returned.  What javascript will return the innerHTML or the HTML of the entire page for Firefox please?
Question by:HometownComp
    LVL 6

    Accepted Solution

    I think you want HTML of entire page. Check out this code works for both ie6 and firefox. :)

    <html id="myhtml">
    <script language="JavaScript">
    function test()

    <body id="mybody" onload="test()">
    <div id="mydiv">

    By Nab
    LVL 9

    Expert Comment

    There is something weird in your title and question, as Firefox does implement the innerHTML property, and it works fine.
    Maybe that's because by "something".innerHTML, you mean that if you have an element with id "mydiv", you try to acces its innerHTML by: myDiv.innerHTML
    Maybe You should use: document.getElementById("myDiv").innerHTML
    (nabsol uses this syntax as you can see though)
    LVL 4

    Expert Comment

    According to the DOM model (and eg. firefox keeps complaining vigorously ?? if you don't ;)) you have to get every element via document.getElementBy* (eg. var el = document.getElementById ("myelementid"); if (el) { /* do sth with the element */ } ).

    Then you'd just use  el.innerHTML = mynewhtmlforelement;

    In case of some mozilla-like browsers not providing the .innerHTML property  get mozInnerHTML.js (google) and add it if you can't find the .innerHTML property, eg. if (!document.body.innerHTML) { document.write ("<SCRI"+"PT language='JavaScript' src='./mozInnerHTML.js'></S"+"CRIPT>"); }

    LVL 4

    Expert Comment

    BTW nabsol:
    But your code doesn't work for Opera 6.x :P

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now