Modify ↓
Ticket #6878 (closed bug: invalid)
html() has weird behavior for divs nested inside anchors in FireFox
| Reported by: | Xodarap | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | manipulation | Version: | 1.4.2 |
| Keywords: | firefox, html, div | Cc: | |
| Blocking: | Blocked by: |
Description
When I use the .html() method to set the inner html of a div which is nested inside an a in firefox 3.5, it wraps what I put inside the html with an a. Sample in firebug:
>>> $('div',$('<a><div></div></a>')).html('test').html()
"<a>test</a>"
(html should be just plain "test".) This doesn't happen in IE 8 or 7 as far as I can tell. Also doesn't happen if it's a span inside an anchor. I'm using 1.4.2, not sure about other versions.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Just to be clear: I don't mean that jQuery is setting the html wrong, because using FireFox's innerHTML gives the problem:
var x = $('div',$('<a><div></div></a>')); x.innerHTML = 'test'; alert(x.html()); // alerts '<a>test</a>'So I think the "bug" is that, in this instance (for reasons I don't understand), jQuery should be using the .empty().append() method instead of the .innerHTML method.