0
I have the following structure:
<div class=duvidas>
<div>
<span>Titulo</span>
<div style='display: none'>Texto</div>
</div>
</div>
The goal is click on in a span
and alter the content
of span
of '+' for '-'
And make the display
of div
of none
for block
.
$('div.duvidas > div').click(function(){
if ($(this).find ('span').css('display') == 'none') {
$(this).find ('span::after').attr('data-content','-');
$(this).find ('div').css('display', 'block');
} else {
$(this).find ('span::after').attr('data-content','+');
$(this).find ('div').css('display', 'none');
}
})
But it’s not working.
Oh, Sam, thanks worked out. But check it out: There’s not just one div.doubtdiv, there are several. How to do for when to open one, also close the div of the other that is open and stay only 1?
– Carlos Rocha
Add this before if:
$('div.duvidas > div').not(this).find("span").removeClass("ativo").end().find('div').hide();
– Sam
It worked! Thank you very much. Now I’ll take a closer look
– Carlos Rocha
how it would look if I wanted to put a Transition effect: height 0.8s; at the time of opening and closing?
– Carlos Rocha
Would have to do in JS because CSS won’t know the height of the element to apply the exact height.
– Sam
ficaria . addClass('active'). css(''Transitions,'height 0.8s')?
– Carlos Rocha
No, you’d have to use . slideToggle
– Sam
I’ll have to leave now, when I get back I’ll show you an example.
– Sam
good. got here: . slideToggle( "slow" ) thanks!
– Carlos Rocha