开发者

div is null in ie but in mozila and opera

开发者 https://www.devze.com 2023-03-20 05:14 出处:网络
<div id=\"a\"></div> if($(\"#a\").is(\':empty\') ) alert(\"empty\"开发者_JAVA技巧); In IE8, it shows alert but Mozila 3.6 and Opera 11 do not show the alert. Why?
<div id="a"></div>

if($("#a").is(':empty') )
      alert("empty"开发者_JAVA技巧);

In IE8, it shows alert but Mozila 3.6 and Opera 11 do not show the alert. Why?

Answer:

if(!$.trim( $("#a").html() ) )
   alert("empty");

this code run in ie and mozila


Your code is valid and should work in those browsers. I tested it in FireFox and Chrome and it works.

Verify that you do not have any other elements in your page that also have an id of a. Most browsers compliant with web standards correctly refuse to acknowledge any duplicated elements and often it causes JavaScripts to fail due to errors.

0

精彩评论

暂无评论...
验证码 换一张
取 消