I'm using jQuery for selecting an element that is targeted (using #test
in the url) and I'm getting a browser-dependent behavior with it.
The code:
### test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="[path_to_]/jquery-1.10.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="test">Hello world</div>
<script>
$(document).ready(function() {
alert($(":target").html());
$(":target").fadeOut(1000).fadeIn(1000);
});
</script>
</body>
</html>
I tried using jsFiddle but this requires the url (which I tried but I was not able to make it work in jsFiddle).
Now, if I open the page test.html#test
...
- with firefox 24.0, it alerts an
Hello world
and fades correctly. - with Chrome 29.0.1547.76, it alerts an
undefined
, and doesn't fade.
I'm using Mac OS X in both.
What am I doing wrong? is this a "feature"?