Solved

Mozilla Equivalent? insertAdjacentHTML

Posted on 2007-04-07
3
408 Views
Last Modified: 2008-01-09
Ive tried (code below) to do something like
document.body.innerHTML = document.body.innerHTML + HM_CurrentMenu.htmlString + "</DIV>"

but doesnt work... code below works in IE but not Moz....

Any suggestions?


document.body.insertAdjacentHTML("BeforeEnd",HM_CurrentMenu.htmlString + "</DIV>");
      menuLyr = document.getElementById(HM_MenuIDPrefix + menucount);
      menuLyr.propertyTransfer = propertyTransfer;
      menuLyr.propertyTransfer();
      HM_CurrentMenu = menuLyr;
      if(!HM_CurrentMenu.hasParent)HM_CurrentTree.treeParent = HM_CurrentTree.startChild = HM_CurrentMenu;
      HM_CurrentMenu.setMenuStyle();
          HM_CurrentMenu.items = HM_CurrentMenu.children;
      HM_CurrentMenu.lastItem = HM_CurrentMenu.items[HM_CurrentMenu.items.length-1];
          for(var i=0; i<HM_CurrentMenu.items.length; i++) {
              it = HM_CurrentMenu.items[i];
            it.siblingBelow = i>0 ? HM_CurrentMenu.items[i-1] : null;
            it.propertyTransfer = propertyTransfer;
            it.propertyTransfer();
            it.itemsetup(i+1);
      }
      HM_CurrentMenu.moveTo(0,0);
      return HM_CurrentMenu;
0
Comment
Question by:B_Dorsey
  • 2
3 Comments
 
LVL 15

Expert Comment

by:stanscott2
Comment Utility
Use standard DOM methods.  If I want to append a DIV at the very end of the HTML, for example, then I'd do this:

var body = document.getElementsByTagName("body")[0];
var newDiv = document.createElement("DIV");
newDiv.innerText = "My new text";
body.appendChild(newDiv);

Other methods (which you can Google "DOM methods") include insertBefore and removeChild.  I can give you more advice if you know just where you want to place your new elements.
0
 
LVL 14

Author Comment

by:B_Dorsey
Comment Utility
Appreciate the help, what I have to do is put the created html into the same position. If I change the code at all it seems to not work , or if I use the method I mentioned above it only shows the last menu...

basically this is a hover menu, when I hover over the top menu it shows them underneath (sub menus).... works fine in IE but just laughs at me in Mozilla...

It looks as though the "document.body.insertAdjacentHTML("BeforeEnd",HM_CurrentMenu.htmlString + "</DIV>");" keeps adding the menu structure just above the last body tag...

Thanks, appreciate any help I can get..

b
0
 
LVL 15

Accepted Solution

by:
stanscott2 earned 500 total points
Comment Utility
Yes, it DOES add the DIV just above the last body tag, but it doesn't mean that you have to position it there.

I would use style="position:absolute;left:0;top:0;display:none;", and then when I had to display it, set the top and left, based on the click element, and then set display to block.  This way you can put it wherever you want.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

762 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

12 Experts available now in Live!

Get 1:1 Help Now