var x = document.querySelector('meta[http-equiv="Content-Type"]');
console.log(x);
x
has a reference to the meta tag if found. It will be null
otherwise, so you can use if (x) {
Here's a way to do it if querySelectorAll
isn't supported (older browsers)
var metas = document.getElementsByTagName('meta');
var found;
for (var i=0; i<metas.length; ++i) {
var meta = metas[i];
if (meta.getAttribute('http-equiv') === "Content-Type") {
found = meta;
break;
}
}
console.log(found);
found
has a reference to the meta tag if it existed. You could do if (found) {
to determine whether or not it exists.