javascript - Internet Explorer innerHTML "Object doesn't support this property or method" - Stack Over

I have a script that checks the value of a Div Id.<div id="hour" style="display:none;

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?

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?

Share Improve this question asked Nov 28, 2011 at 3:14 AlexAlex 1,4004 gold badges15 silver badges19 bronze badges 3
  • Which version of IE? Works fine for me in IE9. jsfiddle/m6SvE – James Montagne Commented Nov 28, 2011 at 3:17
  • don't use innerHTML. Check out [this question!!][1] [1]: stackoverflow./questions/8267245/… – Vicky Commented Nov 28, 2011 at 9:39
  • don't use innerHTML. Check out [this question!!][1] [1]: stackoverflow./questions/8267245/… – Vicky Commented Nov 28, 2011 at 9:39
Add a ment  | 

2 Answers 2

Reset to default 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;

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

Check out this question

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745500501a4630392.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信