Reputation: 2859
How is this possible?
title.innerHTML = 'blah';
alert(title+' : '+title.innerHTML+' : '+title.outerHTML);
Gives me an alert stating:
[object HTMLHeadingElement] : undefined : undefined
In Chrome v28. How?
Upvotes: -2
Views: 189
Reputation: 733
You need to append the element into the DOM first, then you will be able to access those properties.
Complete your createContent
function with appendChild
to insert the created content in the DOM and then returning that node.
Upvotes: 0
Reputation: 2859
I'd previously assigned title to the 'title' attribute of an Element.
function createContent() {
var content = document.createElement('div');
var title = document.createElement('h1');
content.title = title;
return content;
}
var content = createContent();
title = content.title;
title.innerHTML = 'blah';
alert(title+' : '+title.innerHTML+' : '+title.outerHTML);
Alerts:
[object HTMLHeadingElement] : undefined : undefined
Assuming I'm using undefined behaviour (misusing title attribute) or a bug.
Upvotes: -1