jqueryjquery-selectorstoggleinternet-explorer-9internet-explorer-7

jquery problem internet explorer 9 and 7


 $(document).ready(function(){
    $("#yanMenu ul").hide();
    $("div#button").click(function(){
        $(this).next().slideToggle("normal");
        });
    });


                        <div id="yanMenu">          
                           <div id="button"><h5>Kategori 1</h5></div>
            <ul>
                <li><a href="#">Secenek 1</a></li>
                <li><a href="#">Secenek 2</a></li>
                <li><a href="#">Secenek 3</a></li>
                <li><a href="#">Secenek 4</a></li>
            </ul>
            </div>
<!-- This code it doesnt work!-->
                        <div id="yanMenu">          
                               <div id="button"><h5>Kategori 1</h5></div>
                <ul>
                    <li><a href="#">Secenek 1</a></li>
                    <li><a href="#">Secenek 2</a></li>
                    <li><a href="#">Secenek 3</a></li>
                    <li><a href="#">Secenek 4</a></li>
                </ul>
                </div>
<!-- This code it doesnt work!-->

It is toggle menu script . When i was copy again this html code, It didnt work in ie9 and ie 7 What Can i do ?


Solution

  • Because you are using the same ID's more than once in the page. ID's should be unique (only one instance per page)

    Try using classes instead.

     $(document).ready(function(){
        $(".yanMenu ul").hide();
        $(".button").click(function(){
            $(this).next().slideToggle("normal");
            });
        });
    
    
         <div class="yanMenu">          
          <div class="button"><h5>Kategori 1</h5></div>
            <ul>
                <li><a href="#">Secenek 1</a></li>
                <li><a href="#">Secenek 2</a></li>
                <li><a href="#">Secenek 3</a></li>
                <li><a href="#">Secenek 4</a></li>
            </ul>
            </div>
       <div class="yanMenu">          
          <div class="button"><h5>Kategori 1</h5></div>
            <ul>
                <li><a href="#">Secenek 1</a></li>
                <li><a href="#">Secenek 2</a></li>
                <li><a href="#">Secenek 3</a></li>
                <li><a href="#">Secenek 4</a></li>
            </ul>
            </div>