JQuery change on click

I am trying to make a minus sign back into a plus sign after the user has closed the consumable text.

Here is the HTML code

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

      

+3


source to share


1 answer


Simple enough using the 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];

+2


source







All Articles