I need ($(“#flip”).click slideToggle ) to perform several times on the same page with same
ID

后端 未结 1 692
死守一世寂寞
死守一世寂寞 2021-01-24 18:52

I have a FAQs page that reads from XML using XSl code, The div for the question and answer will be repeated as much as the number of records in the XML.

This is the XSL

相关标签:
1条回答
  • 2021-01-24 19:56

    HTML 101: Ids are singular, you can not have more than one item with the same id!

    Use a class! Use next()

    HTML:

    <div class="question">XXX</div>
    <div class="answer">YYY</div>
    <div class="question">XXX</div>
    <div class="answer">YYY</div>
    <div class="question">XXX</div>
    <div class="answer">YYY</div>
    

    JavaScript:

    $(document).on("click",".question", function(){
         $(this).next().toggle();   
    });
    

    Example

    http://jsfiddle.net/8xvTM/1/

    0 讨论(0)
提交回复
热议问题