admin管理员组文章数量:1024625
The document.createElement('a') tag is not working in IE8 in this snippet of code. It works fine in chrome and firefox. When I check through IE, it seems as if its the first line of code that's broken.
item = document.createElement('a');
item.setAttribute('id', 'memorize');
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.setAttribute('class', 'menu_button');
item.onclick = function() {redirect('memorizor', 'memorize', 0);};
menu_div.appendChild(item);
Does anybody know why this is the case, and if there is a crappy browser workaround? I haven't been able to find the workaround.
The document.createElement('a') tag is not working in IE8 in this snippet of code. It works fine in chrome and firefox. When I check through IE, it seems as if its the first line of code that's broken.
item = document.createElement('a');
item.setAttribute('id', 'memorize');
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.setAttribute('class', 'menu_button');
item.onclick = function() {redirect('memorizor', 'memorize', 0);};
menu_div.appendChild(item);
Does anybody know why this is the case, and if there is a crappy browser workaround? I haven't been able to find the workaround.
Share Improve this question edited Aug 9, 2017 at 7:30 FelixSFD 6,10210 gold badges46 silver badges130 bronze badges asked Sep 11, 2011 at 10:52 DaveDave 11 gold badge1 silver badge1 bronze badge 4- Wele to SO. Please always quote the exact error message you are getting. Also, seeing as it's a JS question, it would be better if you showed the final generated HTML/JS instead of the PHP source – Pekka Commented Sep 11, 2011 at 10:54
-
1
How have you determined that
createElement
isn't working? – Michael Mior Commented Sep 11, 2011 at 10:55 -
Broken how? What errors do you get? What debugging tools are you using? What makes you think the problem is with the first line of code? Why are you showing us PHP that generates JavaScript instead of the JavaScript itself? Why are you using
setAttribute
which is known to be broken in many versions of IE (especially for setting class)? – Quentin Commented Sep 11, 2011 at 10:56 - Possible duplicate of createElement error in IE8 – FelixSFD Commented Aug 9, 2017 at 7:30
1 Answer
Reset to default 2Couple of things that might "break" the functionality.. try this instead:
item = document.createElement('a');
item.id = 'memorize';
item.href = "#";
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.className 'menu_button';
item.onclick = function() {
redirect('memorizor', 'memorize', 0);
return false;
};
menu_div.appendChild(item);
First, assign the id
directly and not via setAttribute
and second, anchor without href
bees mere text, not link so you must assign that attribute.
The document.createElement('a') tag is not working in IE8 in this snippet of code. It works fine in chrome and firefox. When I check through IE, it seems as if its the first line of code that's broken.
item = document.createElement('a');
item.setAttribute('id', 'memorize');
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.setAttribute('class', 'menu_button');
item.onclick = function() {redirect('memorizor', 'memorize', 0);};
menu_div.appendChild(item);
Does anybody know why this is the case, and if there is a crappy browser workaround? I haven't been able to find the workaround.
The document.createElement('a') tag is not working in IE8 in this snippet of code. It works fine in chrome and firefox. When I check through IE, it seems as if its the first line of code that's broken.
item = document.createElement('a');
item.setAttribute('id', 'memorize');
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.setAttribute('class', 'menu_button');
item.onclick = function() {redirect('memorizor', 'memorize', 0);};
menu_div.appendChild(item);
Does anybody know why this is the case, and if there is a crappy browser workaround? I haven't been able to find the workaround.
Share Improve this question edited Aug 9, 2017 at 7:30 FelixSFD 6,10210 gold badges46 silver badges130 bronze badges asked Sep 11, 2011 at 10:52 DaveDave 11 gold badge1 silver badge1 bronze badge 4- Wele to SO. Please always quote the exact error message you are getting. Also, seeing as it's a JS question, it would be better if you showed the final generated HTML/JS instead of the PHP source – Pekka Commented Sep 11, 2011 at 10:54
-
1
How have you determined that
createElement
isn't working? – Michael Mior Commented Sep 11, 2011 at 10:55 -
Broken how? What errors do you get? What debugging tools are you using? What makes you think the problem is with the first line of code? Why are you showing us PHP that generates JavaScript instead of the JavaScript itself? Why are you using
setAttribute
which is known to be broken in many versions of IE (especially for setting class)? – Quentin Commented Sep 11, 2011 at 10:56 - Possible duplicate of createElement error in IE8 – FelixSFD Commented Aug 9, 2017 at 7:30
1 Answer
Reset to default 2Couple of things that might "break" the functionality.. try this instead:
item = document.createElement('a');
item.id = 'memorize';
item.href = "#";
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $); ?>";
item.className 'menu_button';
item.onclick = function() {
redirect('memorizor', 'memorize', 0);
return false;
};
menu_div.appendChild(item);
First, assign the id
directly and not via setAttribute
and second, anchor without href
bees mere text, not link so you must assign that attribute.
本文标签: javascriptdocumentcreateElement is not working in IE8Stack Overflow
版权声明:本文标题:javascript - document.createElement is not working in IE8 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745616860a2159341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论