I create new html element. And initialize its value. Then when I try to reach for its title by el.title
, it returns undefined
. However I can reach by getElementsByTagName("title")
The example is below;
var el = document.createElement( 'html' );
el.innerHTML = "<!DOCTYPE html><html><head><title>HTML Reference</title></head><body>The content of the document......</body></html>";
console.log(el.title)
**undefined**
//but the following returns the title
el.getElementsByTagName("title")[0].text
"HTML Reference"
Why this is happening? Why el.title
returns undefined
?
The title
property of an HTML element object maps on to the title
attribute, it doesn't find the first title element descendant.
You would get a result if you had <html title='bad place for a title'>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments