0

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?

1
  • What is title? Please show us the code that sets that variable.
    – jfriend00
    Oct 12, 2013 at 8:08

2 Answers 2

1

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.

0

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.

1
  • To clarify, content.title casts to string.
    – Max
    Oct 12, 2013 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.