Note that there are some explanatory texts on larger screens.

plurals
  1. POdrop-down menu JS
    primarykey
    data
    text
    <p>I am making a drop-down menu for my Website but I am not a boss in JavaScript so I take a ready-made drop-down menu in Internet and I improve that. But when I would it replace my </p> <pre><code>&lt;a href="" title="Afficher le sous-menu"&gt;Voir Plus&lt;/a&gt; </code></pre> <p>It work but when I click again on this links, the script no longer works.</p> <p>The example here : <a href="http://jsfiddle.net/LZfY3/3/" rel="nofollow">http://jsfiddle.net/LZfY3/3/</a>. And the code:</p> <p>CSS</p> <pre><code>#navigation { margin: 0; padding: 0; color: #fff; width: 630px; font: 1.2em "Trebuchet MS", sans-serif; background: #ccc url(subMenu.png) 0 0 repeat-x; } #navigation h2 { margin: 0 0 0 0; } #navigation h2 { display: block; padding: 4px 10px; color: #fff; text-decoration: none; background: #000 url(menu-item.png) left bottom no-repeat; } #navigation .subMenuHidden, #navigation .toggleSubMenu{ clear:both; } #navigation .subMenuHidden, #navigation .subMenuVis { font-size: .8em; font-size: .9em; margin: 0; padding: 0; } #navigation div.subMenuHidden a { padding: 3px 20px; float:right; } &lt;!--[if lte IE 6]&gt; li { height: 1px; } </code></pre> <p>JavaScript</p> <pre><code> &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt; $(document).ready( function () { // On cache les sous-menus // sauf celui qui porte la classe "open_at_load" : $("div.subMenu:not('.open_at_load')").hide(); // On selectionne tous les items de liste portant la classe "toggleSubMenu" // et on remplace l'element span qu'ils contiennent par un lien : /*$("div.subMenuHidden span").each( function () { // On stocke le contenu du span : var TexteSpan = $(this).text(); $(this).replaceWith('&lt;a href="" title="Afficher le sous-menu"&gt;' + TexteSpan + '&lt;/a&gt;') ; } ) ;*/ // On modifie l'evenement "click" sur les liens dans les items de liste // qui portent la classe "toggleSubMenu" : $("div.subMenuHidden &gt; a").click( function () { // Si le sous-menu etait deja ouvert, on le referme : if ($(this).prev("div.subMenu:visible").length != 0) { $(this).prev("div.subMenu").slideUp("normal", function () {$(this).next("a").replaceWith('&lt;a href="" title="Afficher le sous-menu"&gt;voir plus/see more&lt;/a&gt;') } ); } // Si le sous-menu est cache, on ferme les autres et on l'affiche : else { $("div.subMenu").slideUp("normal", function () { $(this).next("a").replaceWith('&lt;a href="" title="Afficher le sous-menu"&gt;voir plus/see more&lt;/a&gt;') } ); $(this).prev("div.subMenu").slideDown("normal", function () { $(this).next("a").replaceWith('&lt;a href="" title="Afficher le sous-menu"&gt;voir moins/see less&lt;/a&gt;') } ); } // On empêche le navigateur de suivre le lien : return false; }); } ) ; </code></pre> <p>HTML</p> <pre><code>&lt;ul id="navigation"&gt; &lt;li class="toggleSubMenu" style="position: static;"&gt;&lt;h2 class="toggleSubMenuH2"&gt;Images / Photos&lt;/h2&gt; &lt;div class="subMenuVis"&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="subMenuHidden"&gt; &lt;div class="subMenu" style="display: none;"&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;a href="" title="Afficher le sous-menu" id="caca"&gt;voir plus&lt;/a&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class="toggleSubMenu" style="position: static;"&gt;&lt;h2 class="toggleSubMenuH2"&gt;Vidéos&lt;/h2&gt; &lt;div class="subMenuVis"&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 100px; width: 178px; background-color: aqua; margin: 10; float: left;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="subMenuHidden"&gt; &lt;div class="subMenu" style="display: none;"&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;div style="height: 80px; width: 142px; background-color: aqua; margin: 0 0 10px 10px; float: left;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;a href="" title="Afficher le sous-menu"&gt;voir plus&lt;/a&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload