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?

Alex
  • 1,398
  • 4
  • 15
  • 19
  • Which version of IE? Works fine for me in IE9. http://jsfiddle.net/m6SvE/ – James Montagne Nov 28 '11 at 03:17
  • don't use innerHTML. Check out [this question!!][1] [1]: http://stackoverflow.com/questions/8267245/how-to-get-value-of-h2-tag-for-a-div-inside-other-div-with-id-using-javascript/8293161#8293161 – Vicky Nov 28 '11 at 09:39
  • don't use innerHTML. Check out [this question!!][1] [1]: http://stackoverflow.com/questions/8267245/how-to-get-value-of-h2-tag-for-a-div-inside-other-div-with-id-using-javascript/8293161#8293161 – Vicky Nov 28 '11 at 09:39

2 Answers2

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;
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
0

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

Check out this question

Community
  • 1
  • 1
Vicky
  • 16,679
  • 54
  • 139
  • 232