Q:

How to remove text between  with javascript

I am using javascript and jquery to change the text inside of an a tag. I was reading that document.getElementById("yearA").innerHTML = ''; would remove the text but it isn't working. I'm not sure if it's because I am adding text to the a tag then trying to remove it or not. Any help with this would be appreciated. Here is my html

document.getElementById("filter-div").style.visibility = "visible";
document.getElementById("yearA").style.visibility = "visible";
document.getElementById("yearA").innerHTML += 'Remove Link';
console.log('Link added')

function hideYear() {
  document.getElementById("yearA").innerHTML = '';
  console.log('Link removed')
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="hidden" id="hiddenTag" />
<div id="filter-div" class="filter-div" style="visibility: hidden;">
  <a id="yearA" onclick="hideYear()" style="visibility: hidden;"></a>
</div>

A:

Jquery based solution
you may try:
$('#yearA').text("");

A:

I'm not sure why you are throwing jquery into the mix, but here is a full example with hide and show functions
HTML:
<input type="hidden" id="hiddenTag" />
<div id="filter-div" class="filter-div" style="visibility: hidden;">
    <a id="yearA" onclick="hideYear(event)"></a>
    <div id="showYear" onclick="showYear(event)" style="visibility: hidden;">
        show year
    </div>
</div>

Javascript:
const year = new Date().getYear();
document.getElementById("filter-div").style.visibility = "visible";
document.getElementById("yearA").innerHTML += "Remove " + year;

function hideYear(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    document.getElementById("showYear").style.visibility = "visible";
    document.getElementById("yearA").innerHTML = "";
}

function showYear(evt) {
    evt.preventDefault();
    evt.stopPropagation();
    document.getElementById("showYear").style.visibility = "hidden";
    document.getElementById("yearA").innerHTML = "Remove " + year;
}

