By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

submenu does'nt appears

P: 2
Hello,
I'm trying to convert an existing menu and submenus in javascript by using DOM methods. The previous one uses only document.write.

I do not manage to show the sub-menus with the onmouseover event.

see lines 18 & 19:


Expand|Select|Wrap|Line Numbers
  1. function affiche(id) {
  2.  
  3. var d = document.getElementById(id);
  4.     for (var i = 1; i<=9; i++) {
  5.         if (document.getElementById('sousmenu'+i)) {document.getElementById('sousmenu'+i).style.display='none';}
  6.     }
  7. if (d) {d.style.display='block';}
  8. }
  9. // <!-- bibliothèques -->
  10. alert('début biblio');
  11. div_biblio = document.createElement('div');
  12. div_biblio.id = 'bibliotheques';
  13. div_biblio.className = 'menu';
  14. lien = document.createElement('a');
  15. lien.href = '#';
  16. lien.textContent = 'Bibliotheques';
  17. div_biblio.appendChild(lien);
  18. div_biblio.onmouseover = affiche('sousmenu3');
  19. div_biblio.onmouseout = affiche();
  20. alert('fin biblio');
  21.  
  22. alert('début biblio_sousmenu');
  23. div_biblio_sousmenu = document.createElement('div');
  24. div_biblio_sousmenu.id = 'sousmenu3';
  25. div_biblio_sousmenu.className = 'sousmenu';
  26. div_biblio_sousmenu.style.display = 'none';
  27. div_biblio_sousmenu.onmouseout = affiche();
  28. div_biblio.appendChild(div_biblio_sousmenu);
  29. alert('fin biblio_sousmenu');
  30.  
  31. alert('début biblio_sousmenu_1');
  32. div_biblio_sousmenu_1 = document.createElement('div');
  33. lien = document.createElement('a');
  34. lien.href = 'http://homeusers.brutele.be/metalcat/bibliotheque-1.htm';
  35. lien.textContent = 'Phase 1';
  36. div_biblio_sousmenu.appendChild(lien);
  37. div_biblio_sousmenu.appendChild(div_biblio_sousmenu_1);
  38. alert('fin biblio_sousmenu_1');
  39.  
  40. alert('début biblio_sousmenu_2');
  41. div_biblio_sousmenu_2 = document.createElement('div');
  42. lien = document.createElement('a');
  43. lien.href = 'http://homeusers.brutele.be/metalcat/bibliotheque-2.htm';
  44. lien.textContent = 'Phase 2';
  45. div_biblio_sousmenu.appendChild(lien);
  46. div_biblio_sousmenu.appendChild(div_biblio_sousmenu_2);
  47. alert('fin biblio_sousmenu_2');
  48.  
  49. div_menu_principal.appendChild(div_biblio);
  50.  
Here the original :
Expand|Select|Wrap|Line Numbers
  1. //document.write( " <div class='menu' id=\"bibliotheques\"onmouseover=\"affiche('sousmenu3');\" onmouseout=\"affiche();\">" );
  2. //document.write( " <a href=\"#\" onclick=\"window.location.reload()\">Biblioth&egrave;ques</a>" );
  3. //document.write( "  <div class=\"sousmenu\" id=\"sousmenu3\" style=\"display:none\" onmouseout=\"affiche();\" >" );
  4. //document.write( "   <div><a href=\"http://homeusers.brutele.be/metalcat/bibliotheque-1.htm\">Phase 1</a></div>" );
  5. //document.write( "   <div><a href=\"http://homeusers.brutele.be/metalcat/bibliotheque-2.htm\">Phase 2</a></div>" );
  6.  
Thank you for help. Sorry for my English.

Regards
Guy Janssens
Brussels
May 28 '16 #1
Share this Question
Share on Google+
1 Reply


P: 2
div_biblio.onmouseover = function() {affiche('sousmenu3')};
div_biblio.onmouseout = function() {affiche()};
May 29 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.