开发者

UL toggle working in FF and not in IE 7

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 fals开发者_如何学Pythone;
    });


});


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜