meta property is undefined

i have some code which takes in a html using ajax and after which it’s meta tags are retrieved.if (request.readyState == 4) var html_text = request.responseText; var parent = document.createElement(‘div’); parent.innerHTML = html_text; var metas = parent.getElementsByTagName(‘meta’); var meta; for(var i=0; i < metas.length; i++) meta …

via HTML Language Development » Search Results » ajax:

meta property is undefined

i have some code which takes in a html using ajax and after which it’s meta tags are retrieved.
if (request.readyState == 4)
var html_text = request.responseText;
var parent = document.createElement(‘div’);
parent.innerHTML = html_text;

var metas = parent.getElementsByTagName(‘meta’);
var meta;

for(var i=0; i < metas.length; i++)
meta = metas[i];
alert(meta.property);
alert(meta.content);
}the html_text does contains meta property and content and the content does show. but why is the meta property showing as undefined? can anyone help me with this?
……………………………………..

Either you have to look for meta.name or you could use meta.getAttribute(“property”).
btw: You are innerHTML’ing the variable html_code but you stored the HTML content in html_text.
……………………………………..

You could try using getAttribute to get the property attribute:
alert(meta.getAttribute(‘property’));I’m not sure why it wouldn’t work your way though.
……………………………………..

What you try here is a kind of creation of a new document, it will not work at least in IE this way.
Put this line
alert(parent.innerHTML)right after:
parent.innerHTML = html_text; …and you will see, that you only get the contents of the body, everything else has been omitted.
If the response is valid xml, request.responseXML should be available, you can inspect it directly(it’s already a document).

For more info: meta property is undefined

HTML Language Development » Search Results » ajax

meta property is undefined

Share this post:

Related Posts

Leave a Comment