Bug Tracker

Modify

Ticket #6572 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

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>')

  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

comment:1 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.