Because its HTML data attribute you can do the following in javascript
email_condition = "qwerty"; //you can set whatever condition you need
console.log(document.querySelector(`span[data-email="${email_condition}"]`));
document
.querySelector(`span[data-email="${email_condition}"]`)
.classList.add("display_none");
display_none is a class defined in css whose definition looks like
.display_none {
display: none;
}
You can refer my [codepen link]:https://codepen.io/ankitt8/pen/pogXJJV
References:
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*
https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
As mentioned in the comment if you want to make the code work for multiple span tags with same email condition you can do as below
email_condition = "qwerty";
let allSpanEmailTag = document.querySelectorAll(
`span[data-email="${email_condition}"]`
);
// note its querySelectorAll previously it was querySelector only
// querySelectorAll returns a list of node based on specified condition.
for (let i = 0; i < allSpanEmailTag.length; ++i) {
allSpanEmailTag[i].classList.add("display_none");
}
The codepen link has been updated so you can refer that!