Pooja Desai
Pooja Desai

Reputation: 227

Whats wrong with this my javascript code ? it is not working in IE8

<html>
<head></head>
<body>
<div class="abcd"></div>
<style>
.new_info {
color:red;
}
</style>
<script>

function getBox(){
    var sende = document.querySelectorAll(".abcd");

    alert(sende[0].hasChildNodes());
    alert(y[0].hasChildNodes());
    if(sende[0].hasChildNodes() == false && sende[0].nodeValue == null){
            var newdiv = document.createElement('div');
            newdiv.innerHTML = "which i want";
            newdiv.className = "new_info";
            sende[0].appendChild(newdiv);
}
}
getBox();

</script>
</body>
</html>

In above code i want to fill div tag having class 'abcd' with some div as childnode having some text like 'which i want'. this work well in other browser but not in IE8. what should i do to work this code in IE8 too ?

Upvotes: 0

Views: 224

Answers (2)

Ahsan Rathod
Ahsan Rathod

Reputation: 5505

What this code is doing alert(y[0].hasChildNodes()); in your code, because of this it is not executing.

See Demo: http://jsfiddle.net/rathoreahsan/NmFNH

i have commented alert(y[0].hasChildNodes()); and it is working.

Upvotes: 0

Blaster
Blaster

Reputation: 9080

The querySelectorAll does not work in IE8 eg only works only in IE8 standards mode and there are bug reports of it when it comes to IE8.

For solution check out:

Sadly or luckily because of these cross browser issues, there exist JavaScript libraries to benefit from which clear all that mess for us internally.

Upvotes: 2

Related Questions