Solved

Mozilla Equivalent? insertAdjacentHTML

Posted on 2007-04-07
3
411 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
ID: 18870718
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
ID: 18870997
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
ID: 18873678
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

832 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