Modify ↓
Ticket #6572 (closed bug: fixed)
bugs about $(..).html() & .text()
| Reported by: | roviury | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.3 | |
| Component: | attributes | Version: | 1.4.2 |
| Keywords: | html bug text | Cc: | |
| Blocking: | Blocked by: |
Description
var obj=$('<span>1<b>2</b>3</span>')
- obj.html(function(){return $(this).text()})
expected result: the content in <span> should be changed from 1<b>2</b>3 to 123 real result: the content become empty
(similar bugs in ".html/text(function(){return $(this).html/text()})")
- obj.html('12&')
expected result: the content will be "12&" real result: the content will be "12", the "&" disappeared.
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.

In the first case, I've clarified in the documentation that the content is emptied before jQuery calls your function. You can use the oldhtml argument to see what it was.
In the second case, a bare ampersand character shouldn't be used in HTML. Instead it should be encoded as &.