Bug Tracker

Opened 13 years ago

Closed 13 years ago

#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:
Blocked by: Blocking:


var obj=$('<span>1<b>2</b>3</span>')

  1. 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()})")

  1. obj.html('12&')

expected result: the content will be "12&" real result: the content will be "12", the "&" disappeared.

Change History (1)

comment:1 Changed 13 years ago by dmethvin

Resolution: fixed
Status: newclosed

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 &amp;.

Note: See TracTickets for help on using tickets.