最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery remove div not working in Internet Explorer - Stack Overflow

programmeradmin6浏览0评论

I'm not really a javascript/jquery coder, I have a very simple code to remove a div that's not working in IE

I'm using this in a Joomla page, so I call it like this:

$document->addScript(".js");//adiciona jquery

And than, in the body document:

<script>
    setTimeout(function() {
        $("#yourDiv").remove();
    }, 50000);
</script>

FireFox and Chrome are (as always) ok. Can someone point out my mistake please? Thanks a lot :)

EDITED ************

I've tryied also with this code no jquery, but always not working in IE (9)

<script>
setTimeout('yourFunction();', 5000);
function yourFunction(){
var div = document.getElementById("yourDiv");
div.parentNode.removeChild(div);
}
</script>

I'm not really a javascript/jquery coder, I have a very simple code to remove a div that's not working in IE

I'm using this in a Joomla page, so I call it like this:

$document->addScript("http://code.jquery./jquery-latest.js");//adiciona jquery

And than, in the body document:

<script>
    setTimeout(function() {
        $("#yourDiv").remove();
    }, 50000);
</script>

FireFox and Chrome are (as always) ok. Can someone point out my mistake please? Thanks a lot :)

EDITED ************

I've tryied also with this code no jquery, but always not working in IE (9)

<script>
setTimeout('yourFunction();', 5000);
function yourFunction(){
var div = document.getElementById("yourDiv");
div.parentNode.removeChild(div);
}
</script>
Share Improve this question edited Feb 25, 2012 at 13:12 Adry asked Feb 25, 2012 at 11:10 AdryAdry 3071 gold badge4 silver badges21 bronze badges 8
  • 2 Does it work in IE with a lower value in the timeout, say 2000? – Rory McCrossan Commented Feb 25, 2012 at 11:12
  • seems like the timeout's too high – Joseph Commented Feb 25, 2012 at 11:15
  • Do you have a sample page you can point to? Nothing there looks like it shouldn't work. – djd Commented Feb 25, 2012 at 11:16
  • Also try setting a type for your <script> tag... – Lix Commented Feb 25, 2012 at 11:16
  • Have you verified that IE is loading the jQuery script? – David Thomas Commented Feb 25, 2012 at 11:16
 |  Show 3 more ments

4 Answers 4

Reset to default 8
<script>
$(document).ready(function(){
    setTimeout(function() {
        $("#yourDiv").remove();
    }, 50000);
});
</script>

Check this fiddle, it's working in ie too.

Maybe this addScript doesn't work. Check if jQuery is loaded:

alert(typeof($));

This alert message would return function or undefined.

I tested this in internet explorer and firefox, works in both.

<html>
<head>
<script type="text/javascript">
    var p = {
        onload: function() {
            setTimeout(
                function() {
                    var div = document.getElementById("myDiv");
                    div.parentNode.removeChild(div);
                },
                3000
            );
        }
    }
</script>
</head>
    <body onload="p.onload()">
    <div id="myDiv" style="height: 50px; width: 50px ;background-color: grey;"></div>
    </body>
</html>

I had this same issue and eventually realized I was using .append to a div and mistakenly also adding my own closing div.

IE is very picky about having elements nested properly.

发布评论

评论列表(0)

  1. 暂无评论