3

I have a script that checks the value of a Div Id.

   <div id="hour" style="display:none;">2</div>
   <div id="min" style="display:none;">1</div>
   <div id="sec" style="display:none;">3</div>

   hour = document.getElementById("hour").innerHTML;
   min = document.getElementById("min").innerHTML;
   sec = document.getElementById("sec").innerHTML;

Works in Chrome, but not in Internet Explorer (Which is where I need it to work)

It gives me the error, "Object doesn't support this property or method"

What is the easier way (preferably one line) to get around this?

3

2 Answers 2

5

I think the problem is that you're naming variables with the same name as DOM elements. I seem to recall IE treating dom elements as first-class citizens, so this may be the cause of your problem.

Try:

var hourHtml = document.getElementById("hour").innerHTML;
var minHtml = document.getElementById("min").innerHTML;
var secHtml = document.getElementById("sec").innerHTML;
Sign up to request clarification or add additional context in comments.

1 Comment

This can also happen if you use a variable name that exists higher up on your page.
0

don't use innerHTML. Apparently its microsoft proprietary function and so not in DOM Standard...

Check out this question

Comments

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.