views:

29

answers:

2

I have an list that toggles with no problem in FF. I need this working IE for it to be production ready.

It seems (IE) to apply the js to the first #orderItem and the first #familiy only. The rest of the items in the list are ignored.

Any help would be great.

A piece of the HTML (large list):

<div class="classificationContainer">

        <ul class="classification" id="orderUL">

        <li id="orderItem" class="ordrheading">
            <div class="order">

                <a href="?nav=search_recherche&amp;lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="By Classification" id="OrdListImage" />

                    Apodiformes (Swifts and Hummingbirds)
                </a>
            </div>

                    <ul class="classification" id="FamilyList">

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&amp;lang=en">


  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Apodidae (Swifts)
                            </a>
                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=423"> Chimney Swift (Chaetura pelagica) </a>

                                </li>

                                </ul>

                    </li>

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&amp;lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Trochilidae (Hummingbirds)
                            </a>

                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=428"> Ruby throated Hummingbird (Archilochus colubris) </a>
                                </li>

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />

                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=433"> Rufous Hummingbird (Selasphorus rufus) </a>
                                </li>

                                </ul>

                    </li>

                    </ul>

        </li></ul></div>

I have the following jquery functions:

<script type="text/javascript">
    $(document).ready(function () {
    // toggle action for the order to familiy
    $("li#orderItem").click(function (event) {
        // toggle the image
        var src = ($("#OrdListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#OrdListImage", this).attr("src", src);

        //toggle the ul
        $('ul#FamilyList', this).toggle($('ul#FamilyList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });

    //toggle action from familiy to speices
    $("li#familiy").click(function () {
        // toggle the image
        var src = ($("#FamListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#FamListImage", this).attr("src", src);            
        //toggle the ul
        $('ul#SpiecesList', this).toggle($('ul#SpiecesList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });


});

A: 

The toggle function provided by jQuery is not guaranteed to work. I lost the reference where I read this (was on jQuery's homepage). I encountered the same problem and (as suggested by jQuery) implemented my own toggle function. I'd suggest trying this, as it's not much work and could provide you a solution.

Anzeo
+1  A: 

Also check if id's are not repeated (there is only one #orderItem, only one #familiy and etc.). "id" attribute must be unique in html document, "class" can be repeated.

egis
That was it. I changed the jquery to the following:$("li[id*='orderItem']")$("li[id*='familiy']")That way it found all ids. I'm using nested repeaters to generate the list. So the ids don't always end up unique.
Arnej65
The purpose of "id" is to be unique. If your html contains more than one "id" of the same value - use "class". Well, if you wish that your html would be w3c valid :)
egis
I changed the reference to the classes of the elements instead.
Arnej65