I am trying to update my snippet to:
1 - If the input has a value output the value to span.Permalink before the event listener updates the span tag
2 - Target the span by a class not an ID. I had to add more then one span tag so I can no longer use an ID
I have the snippet working if the span tag has an ID, but now I need to the input value to update all the span tags with a class of .Permalink.
I have tried getElementsByClassName, getElementByClassName and $(.span.Permalink and a few other ways.
window.onload = function() {
const nameField = document.querySelector('[name="accsc_settings[accsc_get_started_home_page_title]"]');
nameField.addEventListener('input', function() {
document.getElementById('Permalink').textContent = this.value.toLowerCase().replace(/ /g, "-");
})
};
<div class="home_page_title">
<input id="nameField" type="text" name="accsc_settings[accsc_get_started_home_page_title]" value="West Coast" data-depend-id="accsc_home_page_title">
</div>
<div>/<span class="Permalink"></span>/about-us/</div>
<div>/<span class="Permalink"></span>/contact/</div>
<div>/<span id="Permalink"></span>/products/</div>