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
Solved

Mozilla Equivalent? insertAdjacentHTML

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

789 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