Although it may seem like a simple question, I am struggling to change the text on my button.
The code for my button in the web browser console is:
<button class="nav-link active" id="coholder-tab" data-toggle="tab" data-target="#coholder" type="button" role="tab" aria-controls="coholder" aria-selected="true">COTITULAR 1 <i class="fa fa-1x fa-trash ml-3 deleteCoholder" aria-hidden="true"></i></button>
I want to be able to click on deleteCoholder
, remove COTITULAR 1
and the trash icon, then set the text to AÑADIR COTITULAR
.
To achieve this, I am using a function in Vue and vanilla JavaScript. Here's my code:
<button class="nav-link" id="coholder-tab" data-toggle="tab" data-target="#coholder" type="button" role="tab" aria-controls="coholder" aria-selected="false" @click="changeTab()">AÑADIR COTITULAR</button>
const changeTab = () => {
let textTab = "COTITULAR 1";
let tabText = document.getElementById("coholder-tab");
let coholder_container = document.getElementById("coholder_container");
let icon = '<i class="fa fa-1x fa-trash ml-3 deleteCoholder" aria-hidden="true"></i>';
tabText.innerHTML = "COTITULAR 1 " + `${icon}`;
if (coholder_container.classList.contains('d-none')) {
coholder_container.classList.remove('d-none');
}
let trahs = document.getElementsByClassName('deleteCoholder');
trahs[0].addEventListener('click', function(e){
document.querySelector('#coholder-tab').innerHTML = 'AÑADIR COTITULAR';
coholder_container.classList.add('d-none');
});
}
I have also tried following this solution, but I still cannot change the text on my button and hide my div. I'm not sure what I'm doing wrong.
Thank you for reading and apologies for my poor English.