FireFox problem with appendChild image to anchor
I have very simple code:
<html>
<head>
<title></title>
<开发者_StackOverflow中文版;/head>
<body>
<input type="button" value="Add Button" onclick="AddButton();" />
<br />
<div id="divBtnContent">
</div>
<script type="text/javascript">
function AddButton() {
var divBtnContent = document.getElementById('divBtnContent');
var anchor = document.createElement('a');
anchor.href = "http://backticket.com.ua";
var image = document.createElement('image');
image.src = "http://backticket.com.ua/Img/addNew.jpg";
anchor.appendChild(image);
divBtnContent.appendChild(anchor);
}
</script>
</body>
</html>
It works perfect in all browsers except FF. Why FF doesn't appendChild image to anchor? Thanks!
I would expect this to be the cause of the problem:
var image = document.createElement('image');
There is no image element in the HTML and XHTML specifications. You probably meant:
var image = document.createElement('img');
After testing in Google Chrome and IE 9 (RC), it appears that they anticipated this kind of developer error and an <img>
element is created for you instead.
- Original fiddle: http://jsfiddle.net/WUFuu/
- Fixed fiddle: http://jsfiddle.net/WUFuu/1/
精彩评论