Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't select HTML5 element's children in IE8 with jQuery selector

I found some posts with similar issues, but this is something different. I upgraded from jQuery 1.4 to 1.4.2 after I read another post, but the problem still presents itself. I also tried running IE 8 in compatibility mode and nothing seemed to work. Of course, it works perfectly well in Chrome.

Here's the markup:

<section class="pleaseWaitButton">
    <p><img src="images/please_wait.png" alt="Please wait" /></p>
    <p><input type="image" src="images/add_to_cart.png" alt="Add to cart"/></p>
</section>

Here's the only jQuery selector that does work in this scenario...

$('.pleaseWaitButton').length // 1

And here's the jQuery selectors that will not work!

$('.pleaseWaitButton').find('input').length // 0
$('.pleaseWaitButton input').length // 0
$('.pleaseWaitButton > p > input').length // 0

Any ideas? Anyone...?

like image 259
jedmao Avatar asked Jul 28 '10 11:07

jedmao


1 Answers

Internet Explorer 8 has quirky support for HTML 5, IE6 and IE7 plain just don't support it.

You need to shiv the HTML 5 elements in order to style and properly use methods/properties such as innerHTML, getElementsByTagName on them.

This will work in IE6-IE8:

<!doctype html> 
<html> 
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> 
<section class="pleaseWaitButton"> 
    <p><img src="images/please_wait.png" alt="Please wait" /></p> 
        <p><input type="image" src="images/add_to_cart.png" alt="Add to cart"/></p> 
</section> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
<script> 
    alert( $('.pleaseWaitButton').find('input').length ) 
    alert( $('.pleaseWaitButton input').length ) 
    alert( $('.pleaseWaitButton > p > input').length ) 
</script> 
</html> 

Live Demo: http://medero.org/html5.html

like image 181
meder omuraliev Avatar answered Oct 18 '22 10:10

meder omuraliev