-3
I would like the "remove time" button on the page not to appear again!
- The page comes with an already time field
- The remove time button does not appear on the rendered page
- When the user clicks on the "add a time" button a new time field appears and the remove button appears right next to the add button
- I would like the Remove Time button to disappear again if the user deletes the add field by leaving only one time as initially on the loaded page
Excerpt from html buttons
<fieldset id="schedule-items">
<legend>Horários disponíveis
<button type="button" id="add_time">+ Novo horário</button>
<button type="button" id="rm-time">- Remover</button>
</legend>
<div class="schedule-item">
<div class="select-block">
<label for="weekday">Dia da semana</label>
<select name="weekday[]" required>
Well, that’s what I implemented in JS but I can’t continue from there, so the remove button goes back to in 'Hide' mode say so, after the user deletes the added time
document.getElementById('rm-time').style.display = 'none'
document.getElementById('add_time').addEventListener('click', showRemoveField)
function showRemoveField() {
const getSchedules = document.querySelectorAll('.schedule-item')
const changeDisplay = document.getElementById('rm-time').style.display = ''
if (getSchedules.length > 1) {
return changeDisplay
} else {
}
}
Carvalho, thanks for the answer, I improved my question, in fact the doubt is very simple, I think I ended up leaving very confused trying to explain too, I’m starting now in this world of programming, forgive me but I didn’t even know jQuery and by your comment I was amazed how easy it was to do with him everything I did with JS by itself and I’m looking for more related content, but then in the section you put was exactly what I have implemented, i would like if the user removes a time leaving only one, the remove button returns to the IDE()
– Samuel Moraes
I reissued the answer. Just by clicking the remove button add an Hide event to it itself.
– Rodrigo Carvalho de Brito
Thank you very much, I managed to do what I wanted to do from a look at the answer I left for you to better understand what I needed ^^
– Samuel Moraes
Beauty! There are several ways to get to the goal and you got it. It was readable, this is important to allow future maintenance. If you can, from a carefully studied jQuery because it simplifies a lot of JS, however, the root JS will enable you to create a world of cool things!
– Rodrigo Carvalho de Brito