Answer the question
In order to leave comments, you need to log in
How can I select all elements except the one clicked when clicked?
Tell me how you can select all elements (li) except for the clicked one?
Looping through an array
<ul class="list-group" v-for="item in items">
<li @click="reciveitems(item)" class="list-group list-group-item"><img :src="item.img" class="rounded mx-auto" :alt="item.name">
<p class="count position-absolute">{{ item.count }}</p>
<p class="name position-absolute">{{ item.name }}</p>
</li>
</ul>
Answer the question
In order to leave comments, you need to log in
we open the Vue documentation and we meet such an example there
<ul id="example-2">
<li v-for="(item, index) in items">
{{ parentMessage }} - {{ index }} - {{ item.message }}
</li>
</ul>
<ul id="example-2">
<li v-for="(item, index) in items" @click="selectAllExcept(index)">
{{ parentMessage }} - {{ index }} - {{ item.message }}
</li>
</ul>
methods: {
selectAllExcept(index) {
this.items.forEach((el, i) => {
if (i !== index) {
el.selected = true;
}
})
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question