2013-02-06 35 views
0

我不能讓我的jQuery工作。無法在jQuery上的點擊功能顯示工作

當div關閉時,我想讓文本「顯示更多」,然後在打開時顯示「少顯示」。

打開時這段文字作品,但它關閉時,它不會改變..

$('.more_content').click(function(){ 
     $('p.show').text($('p.show').is(':visible') ? 'Show less' : 'Show more'); 
     $('#extra_content').slideToggle('fast')    
    }); 
+0

嗯,這是因爲你沒有隱藏它,所以它總是可見的。 – Colleen

回答

2

聲明

$('p.show').is(':visible') 

應該是:

$('#extra_content').is(':visible') 
0
$('.more_content').click(function(){ 
$('#extra_content').is(':visible') ? $('p.show').text('Läs mer om oss') : $('p.show').text('Läs mindre om oss') ; 
$('#extra_content').slideToggle('fast') 
enter code here});