admin管理员组文章数量:1425240
In IE 8, jQuery acts as I would expect:
$('div',$('<a><div></div></a>')).html('test').html()
"test"
In FireFox:
$('div',$('<a><div></div></a>')).html('test').html()
"<a>test</a>"
It puts anchors around what I wanted. Does anyone know why this would happen?
EDIT: Setting this with plain javascript (i.e. setting innerHTML) causes the problem. So I guess my real question is: why does firefox change what I set? Is this part of some esoteric specification, or is it a bug?
In IE 8, jQuery acts as I would expect:
$('div',$('<a><div></div></a>')).html('test').html()
"test"
In FireFox:
$('div',$('<a><div></div></a>')).html('test').html()
"<a>test</a>"
It puts anchors around what I wanted. Does anyone know why this would happen?
EDIT: Setting this with plain javascript (i.e. setting innerHTML) causes the problem. So I guess my real question is: why does firefox change what I set? Is this part of some esoteric specification, or is it a bug?
Share Improve this question edited Apr 23, 2012 at 15:02 Stian 1,2992 gold badges19 silver badges38 bronze badges asked Aug 5, 2010 at 17:22 XodarapXodarap 11.9k12 gold badges63 silver badges97 bronze badges4 Answers
Reset to default 5Wrapping an <a>
around a <div>
is invalid html. Maybe Firefox is fixing it for you on the fly and returning the valid html?
well, firefox maybe knows you're breaking the rules.
but it did not know you did if you use .append()
.
$('div',$('<a><div></div></a>')).html('').append('test').html(); // give you 'test'
Not sure if it applies here (as we dont know which doctype you're using) but wrapping an <a>
around a <div>
is perfectly valid in html5, but Firefox obviously isn't up to speed on that yet. I'm guessing FF4 will be though
Had the same issue with Firefox 3.6.18 (4.x, 5.x renders page correctly). Quick and dirty fix which I came up was to wrap everything inside <a> with <span>.
本文标签: javascriptdiv nested inside a gives weird innerHTML result in FireFoxStack Overflow
版权声明:本文标题:javascript - div nested inside a gives weird innerHTML result in FireFox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745440960a2658446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论