Question about "Parent" in Jquery

Asked

Viewed 60 times

1

I want when I click on class atendimento to classhorarios keep display:block

Follows my HTML:

<div class="margin-top-30 pai">
    <ul class="horarios">
        <li class="horariosFechar">x</li>            
    </ul>
    <div class="unidadesTotal">
        <div style="display:none" class="unidadesConteudo margin-top-25">
            <div class="atendimento unidadesAtendimento margin-top-15 f-left">hor&aacute;rio de atendimento</div>
        </div>
    </div>
</div>

And my JQUERY:

$( ".atendimento" ).click(function() {
    $(this).parent.parent.parent.find( ".horarios" ).css('display','block');
});

I mean, I’m coming back with the parent to give the click, what happens, is that it is not working.

1 answer

4


You forgot the parentheses after the parent. An alternative to avoid this amount of parent is to use parents as follows:

$(this).parents('.pai').find('.horarios').show();
  • Damn, that noobisse mine, I’m even embarrassed, Ahaaha. That was it.

  • The parents() didn’t work.

  • neither. However, the parent() has worked for you

  • As he said, you have to avoid using that amount of Parent, depending on the relativeses may be that one of them is an orphan. (laughs)

  • Neither the code originally posted by the OP nor yours worked as expected. His because he performs a routine at the click of a hidden DIV: How will it be clicked if it is hidden? And your why it lacks trigger context: When will this routine of yours be executed? At the same click of the hidden DIV? I suggest reviewing the answer of, who knows, supplement it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.