JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" class="myClass_toBeRemoved">link1</a>
<a href="#" class="myClass_toBeRemoved">link2</a>
<a href="#" class="myClass_tobeKept">link3</a>
<a href="#" class="myClass_tobeKept">link4</a>
JavaScript
$('document').ready(function () {
// get reference to all the links. This will be analogous to your headlis var
var allAnchors = $('a');
// final array of link on which .click will be bound
var finalArrayOfLinks = [];
// populate array with all links
allAnchors.each(function () {
finalArrayOfLinks.push(this);
});
// remove elements from finalArrayOfLinks array with class containing toBeRemoved. This is where your custom logic will come in place, condition might differ. you may want to check the html text between anchor or it can be anything by which you will identify which links are to be skipped. I have used class attribute to identify
allAnchors.each(function () {
if ($(this).attr('class').indexOf('toBeRemoved') > -1) {
finalArrayOfLinks.splice(this, 1);
}
});
// assign final array to your original variable so that no changes needed in rest of the code
allAnchors = finalArrayOfLinks;
// bind .click to elements in final elements
$(allAnchors).each(function () {
$(this).click(function () {
alert('I was not removed from array. My onclick still works');
});
});
});