jQuery: The Write Less, Do More JavaScript Library

Ticket #1386 (closed bug: fixed)

Opened 1 year ago

Last modified 1 year ago

inconsistent .html() and .text()

Reported by: mrtwice99 Assigned to: john
Type: bug Priority: major
Milestone: 1.1.4 Component: core
Version: 1.1.3 Keywords:
Cc: Needs: Test Case

Description

Discussion of this bug: http://groups.google.com/group/jquery-en/browse_thread/thread/9a7e4a989106f57b/b5bbedf927fab901?lnk=gst&q=rsyring&rnum=2#b5bbedf927fab901


Summary Follows


The docs say that .text() is similar to .html() except that all the html formatting gets stripped out. However, .text() does not operate the same way as .html() when given a number object instead of a string.

Live Example:

http://rcs-comp.com/code_examples/text_function_bug/

I have some code that has a three column table in it. When the user updates some number values in one of the two columns, I have some JS that sums those columns and updates the value in the third column with that info. When updating the third column, which his a TD element, I tried to use text() to do it:

var total = col1Total + col2Total; $('#wi_medical_total').text(total);

However, that did not work because the text in the cell never seemed to get updated. So, I I changed the code to use .html() instead of .text() :

var total = col1Total + col2Total; $('#wi_medical_total').html(total);

and it worked just fine. So, I did some more playing and came up with this:

var total = 5 + 5 + 'p'; $('#wi_medical_total').text(total);

Which finally worked and changed the text correctly to "10p". FYI, "p" was just a random character.

Attachments

Change History

Changed 1 year ago by mrtwice99

Sorry, this shouldn't be in the Ajax component. It should be a 'core' issue I believe.

Changed 1 year ago by john

  • need changed from Review to Test Case
  • component changed from ajax to core

Changed 1 year ago by john

  • owner set to john

Changed 1 year ago by john

  • status changed from new to closed
  • resolution set to fixed

Fixed in SVN rev [2421].

Note: See TracTickets for help on using tickets.