Solved

Mozilla Equivalent? insertAdjacentHTML

Posted on 2007-04-07
3
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
close pop up windows when logout or main window closes 17 87
Why am I getting SyntaxError: missing ; before statement error 39 83
Error Handler 8 45
Natural height and jquery 6 41
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
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…

752 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