3

Im trying to make the "Minus" sign turn back into the plus sign after the user has closed the expendable text.

Here is the code HTML

<p class="textDropTitle"><span class="textDropLogo"></span>Title</p>
    <div class="textDropSub"><p>This is my text Below</div>
    <p class="textDropTitle"><span class="textDropLogo">+</span>Title</p>
    <div class="textDropSub"><p>This is my text Below</div>
    <p class="textDropTitle"><span class="textDropLogo">+</span>Title</p>
    <div class="textDropSub"><p>This is my text Below</div>

jQuery

$(".textDropSub").hide();

$('.textDropLogo', this).text('+');

$(".textDropTitle").click(function() {
    $(this).next().toggle('fast');
    $('.textDropLogo', this).text('-');
});

1 Answer 1

2

Quite simple using a Conditional Ternary Operator (?:)

$(".textDropTitle").click(function() {

    $(this).next().toggle('fast');

    var $el = $('.textDropLogo', this);
    $el.text( $el.text() == '+' ? '-' : '+' );

});

[condition] ? [if is true] : [if is false] ;

READ MORE

Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly, thank you for the fast response. Will vote up as soon as I can

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.