基本选择器问题

时间:2016-01-23 12:09:04

标签: jquery

我试图在点击链接时显示隐藏的div(并隐藏其他一组)。这是最简单的例子的代码,一个链接,一个div。 出于某种原因,它无法正常工作。如果我按类选择div,罚款,显示,如果我按ID选择它,它就不会。激活链接上的addClass(' active')有效,所以我知道我的程序流程和链接的选择是正确的。我做错了什么?

<script>  
jQuery("document").ready(function($) {

    $( "#deal-147" ).click( function() {

        if ($(this).hasClass('active') ){ // if we clicked on this just hide it and remove class active

            $( this ).removeClass('active');
            $( ".deal-summary" ).hide();    

        } else {


            $( ".deal-link" ).removeClass('active'); //remove class from all
            $( "#deal-summary-147" ).show(); //doesn't work
            $( "#deal-summary-147" ).addClass('reveal'); //doesn't work
            //$( ".deal-summary" ).show(); //does work
            $( "#deal-147" ).addClass('active');//does work

        }
    } );
});
</script>

<a id="deal-147" class="deal-link" href="#">Deal summary</a>
<div id="#deal-summary-147" class="deal-summary">
 <p>some text here...</p>
</div>

0 个答案:

没有答案