Solved

Mozilla Equivalent? insertAdjacentHTML

Posted on 2007-04-07
3
410 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regular Expression Calculator Tester 2 59
Split in Javascript 5 31
bootstrap footer centering and expand problems 7 29
how can i count words? 2 18
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-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now