Albin Ferm
Albin Ferm

Reputation: 101

Cant get the show on click function on jQuery to work

I cant get my jQuery to work.

I want the text "Show more" when the div is closed, then "Show less" when it is open.

This text works when it opens, but when it closes it wont change..

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

Upvotes: 0

Views: 70

Answers (2)

Albin Ferm
Albin Ferm

Reputation: 101

$('.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});

Upvotes: 0

hjpotter92
hjpotter92

Reputation: 80629

The statement

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

should be:

$('#extra_content').is(':visible')

Upvotes: 2

Related Questions