jmcreative
asked on
jQuery chokes on a page without doctype .dtd file reference
Hello everyone.
I have a little piece of jquery running... i found it chokes on IE.. IE always renders the "else"
Firefox and Chrome work perfect.
If you duplicate this code in 2 files and then put the doc type for one as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
and the doc type for the second as
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The rest of the file is the same.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<div id="rightFloat" style="width:200px;border: thin solid pink;">
HEY I Am Here!
</div>
<img src="justj.jpg" />
<script language="javascript">
if ($('img[src = "justj.jpg"]').length) {
//if the image with that src exists
document.getElementById('r ightFloat' ).style.di splay = "block";
document.write("Yippeee.. I display block!")
} else {
document.getElementById('r ightFloat' ).style.di splay = "none";
document.write("I am the else statement, I display none!")
}
</script>
</html>
You notice that in firefox and chrome - BOTH WORK and the condition pops up the div.
You'll notice in IE, that the one without the .dtd reference in the doc type does NOT WORK
If I can not change the doc type.. is there anything else to consider why IE would choke on this particular code snippet and not other instances of jquery?
I have a little piece of jquery running... i found it chokes on IE.. IE always renders the "else"
Firefox and Chrome work perfect.
If you duplicate this code in 2 files and then put the doc type for one as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
and the doc type for the second as
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The rest of the file is the same.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<div id="rightFloat" style="width:200px;border:
HEY I Am Here!
</div>
<img src="justj.jpg" />
<script language="javascript">
if ($('img[src = "justj.jpg"]').length) {
//if the image with that src exists
document.getElementById('r
document.write("Yippeee.. I display block!")
} else {
document.getElementById('r
document.write("I am the else statement, I display none!")
}
</script>
</html>
You notice that in firefox and chrome - BOTH WORK and the condition pops up the div.
You'll notice in IE, that the one without the .dtd reference in the doc type does NOT WORK
If I can not change the doc type.. is there anything else to consider why IE would choke on this particular code snippet and not other instances of jquery?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER