Bug Tracker

Modify

Ticket #3417 (closed bug: invalid)

Opened 6 years ago

Last modified 6 years ago

.text() method doesn't work as expected

Reported by: dimik Owned by:
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: text Cc:
Blocking: Blocked by:

Description

i suppose when use the $('div.someclass').text() - it will empty div's textNode. But it also remove all elementNode inside.

Change History

comment:1 Changed 6 years ago by dimik

textarea formatting cut my quotes i mean $('div.someclass').text('empty value or some text here')

comment:2 Changed 6 years ago by dimik

i think it in the line 188:

return this.empty().append( (this[0] && this[0].ownerDocument
document).createTextNode( text ) );

may be use something like this instead:

jQuery.each( this, function(){

jQuery.each( this.childNodes, function(){

if ( this.nodeType == 3 )

this.parentNode.removeChild(this);

});

});

return this.append( (this[0] && this[0].ownerDocument
document).createTextNode( text ) );

comment:3 Changed 6 years ago by scott.gonzal

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

This is intended behavior. Think about the text that should be returned for this HTML:

<div>foo<span>bar</span>baz</div>

If you were to try to change the text of that div without changing the descendant elements, you wouldn't have the control you need. Another way to think about it is that if you set the text of an element and then immediately get the text of that element, you shouldn't get a result that differs from what you just set.

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.