0

内部htmlを持つarticle要素が.article-rowあり、.content.

.contentは非表示で、.article-rowクリック.contentすると表示されます。しかし、現在クリックされているアイテムの が唯一のアイテムになるように、他articleのを.hide()使用したいと思います。.content

$('.article-row').click(function(e){
    e.preventDefault();
    if($(this).parent().find('.content').is(':visible')){
        $('.content').hide();
    }else{
        $('.content').hide();
        $(this).parent().find('.content').show();
    }
});

$('.close').click(function(e){
    $(this).parent().hide();    
});

jsフィドル

4

1 に答える 1

1

これには、jquery で not 関数を使用できます。私はあなたのフィドルをこのように更新しました。チェックしてください。

$('.article-row').click(function(e){
   e.preventDefault();
   $('.article-row').not(this).hide();
if($(this).parent().find('.content').is(':visible')){
    $('.content').hide();
}else{
    $('.content').hide();
    $(this).parent().find('.content').show();
}
 });

 $('.close').click(function(e){
  $('.article-row').show();
  $(this).parent().hide();    
 });

http://jsfiddle.net/QpA6b/2/

于 2013-09-18T11:41:54.983 に答える