Answer the question
In order to leave comments, you need to log in
Why does the script not work on the first click?
I hang an event on an element:
<div class="item-card__header" @click="showDocuments($event)">
showDocuments: function (event) {
if(event.currentTarget.nextElementSibling.style.display == 'none') {
event.currentTarget.nextElementSibling.style.display = 'block';
} else {
event.currentTarget.nextElementSibling.style.display = 'none';
}
},
Answer the question
In order to leave comments, you need to log in
This is the wrong approach. Make the showDocs property, which will be responsible for the visibility of the element, and add v-show="showDocs"
. The click handling will look like this: @click="showDocs = !showDocs"
.
Well, why your code does not work as it should - it's because the default value style.display
is not none at all, but an empty string (most likely - you hide the element through css, right?).
UPD. Taken from the comments:
This will not work, because I display the elements in the v-for loop.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question