Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Adding class to div if it has parent with same class

right now I'm working on Episerver webapp and Im new to vue.js so I need your help.. I need to detect accordion inside accordion so I can give it left margin thus indent, so its clear its accordion inside accordion and not just two accordions after one another.

current cshtml looks like this :

<generic-component inline-template class="vue-block-app" server-rendered="true" >
<div>
    <div v-bind:class="{isNested: isNested('@collapseId','collapsible-list-item-block')}" class="collapsible-list-item-block grid @Model.GetHiddenPrintClassName">
        <div class="collapsible-list-item-block__heading" id="headingOne" @@click="collapsibleClicked('@collapseId')">
            <div class="@collapseButtonClass" v-b-toggle="'@collapseId'" variant="primary">
                <div class="text-line-content">@Html.PropertyFor(m => m.Title)</div>
                <div class="icon-wrap float-right">

                    <span class="collapseIcon">@{Html.RenderCollapseIcon();}</span>
                    <span class="expandIcon">@{Html.RenderExpandIcon();}</span>
                </div>
            </div>
        </div>
        <b-collapse id="@collapseId" @collapsedByDefault class="collapsible-list-item-block__content" style="display: none;">
                @Html.PropertyFor(m => m.Content)
        </b-collapse>
    </div>
</div>

my vue file looks like this:

<script>
import componentMounted from '../mixins/component-mounted';
export default {
    mixins: [componentMounted],
    data() {
        return {
            isNestedAccordion: false,

        };
    },
    computed: {

    },
    methods: {
        collapsibleClicked(id) {
            $(window).trigger("collapseClicked", [id]);
        },
        isNested(id, className) {
            var element = document.getElementById(id);
            do {
                if (element.classList && element.classList.contains(className)) {
                    console.log("true")
                    return true;
                }
                element = element.parentElement.parentElement;
            } while (element);
            console.log("false")
            return false;
        }
    }
}

and css class .isNested{margin-left:20px;}

what Im I doin wrong that Im not getting class to my div.... Btw, when I had my isNested() inside collapsibleClicked() it worked just fine on click... what am I missing?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda