I am trying to highlight any element that has English characters. The code is highlighting the parent elements also. How can I stop this?
Actually, the regular explession is not important. I just need to highlight the single element in any condition. Please only JavaScript not JQuery. Thank you.
HTML
<!DOCTYPE html>
<html>
<body>
<h1>日本</h1>
<div>
<div>日本</div>
<div>1234</div>
</div>
<div>
<div>abcd</div>
<div>日本</div>
</div>
<script>
document.querySelectorAll('*').forEach((ele) => {
let chars = /[a-zA-Z]/;
if(ele.textContent.match(chars)) {
ele.style.border = "3px solid red";
}
});
</script>
</body>
</html>