Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

javascript - jQuery toggle class on child element

I have list of links, and if you click on any of them, it will toggle show/hide text below it in separate div. Also it hides all other divs if one of them is shown This code manages it:

$(document).ready(function(){
$('.targetDiv').hide();
    $('.hideshow').click(function () {
        $('#div' + $(this).attr('target')).toggle('').siblings('.targetDiv').hide('');
});});

And this is what the link looks like

<a class="hideshow" target="1"><div class="cennikPlus"><i class="fa fa-plus-square"></i></div>Something something</a>

What i need to do is to change

fa-plus-square

to

fa-minus-square

when open and back, when closed. I found "toggleClass" which should be useful in this case, but I am not sure how to select i inside div inside a

Can you help me with this?

Also the website is here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Find the <i> and call toggleClass

$(this).find("i").toggleClass("fa-plus-square fa-minus-square")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...