0

I've written this sample code to print the length of x. But for some reason, I am not getting anything! Help!

<html>
<head>
<script type = "text/javascript">
function myF()
{
   var x = [1,2,3,4];
   var y = document.getElementById("thing");
   y.innerHtml = x.length;
}
</script>
</head>

<body onload = "myF();" >

<div id = "thing" >
PRINT TEST
</div>

</body>
</html>

1 Answer 1

7

The property name is innerHTML rather than innerHtml.

Sign up to request clarification or add additional context in comments.

5 Comments

Why does the Firefox error console not return an error when this is done?
@Unkwntech: Why should it? DOM nodes are objects, so you're free to add any property you like - even ones named 'innerHtml'...
@Unkwntech: Because That's JavaScript's syntax to assign new properties to instantiated objects. So what happened in that line was the object stored in 'y' had a new property name 'innerHtml' attached and assigned the length of array x.
I thought so, it was asked for the sake of the question asker.
I'd look at using jQuery(el).html() instead. It'll be future proof.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.