Bug Tracker

Modify

Ticket #4548 (closed bug: duplicate)

Opened 4 years ago

Last modified 2 years ago

jquery.text bug

Reported by: jidixuelang Owned by:
Priority: low Milestone:
Component: manipulation Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

[code] alert($('title').text()); code

As using 'jquery.text' to fetch the text of document.title,I will get nothing with IE! But work fine,when i use firefox or chrome!

I see,IE has a question at the realization of title-node. Executeing the following code with IE,i will get zero.However,the 'one' is expected and truly at the other browser! [code] document.getElementsByTagName('title')[0].childNodes.length code

Also , I find modifing the source code of jquery can avoid this question,Only with which part about 'jquery.text'. [code]

/ @id jQuery.text /

text: function( text ) {

if ( typeof text != "object" && text != null )

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

var ret = "";

jQuery.each( text
this, function(){

ret += this.innerText!=undefined?

this.innerText:this.textContent!=undefined?

this.textContent:;

});

return ret;

},

code

So i think this problem maybe has the better one resolvent!

Change History

comment:1 Changed 4 years ago by jidixuelang

As the format is bad, I rewrite the above content!

--code start--

alert($('title').text());

--code end--

As using 'jquery.text' to fetch the text of document.title,I will get nothing with IE! But work fine,when i use firefox or chrome!

I see,IE has a question at the realization of title-node. Executeing the following code with IE,i will get zero.However,the 'one' is expected and truly at the other browser! --code start--

document.getElementsByTagName('title')[0].childNodes.length

--code end--

Also , I find modifing the source code of jquery can avoid this question,Only with which part about 'jquery.text'.

--code start--

/ @id jQuery.text /

text: function( text ) {

if ( typeof text != "object" && text != null )

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

var ret = "";

jQuery.each( text
this, function(){

ret += this.innerText!=undefined?

this.innerText:this.textContent!=undefined?

this.textContent:;

});

return ret;

},

--code end--

So i think this problem maybe has the better one resolvent!

comment:2 Changed 3 years ago by dmethvin

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

The cross-browser way to get a document's title is the document.title property.

comment:3 Changed 2 years ago by jitter

  • Status changed from closed to reopened
  • Component changed from unfiled to manipulation
  • Priority changed from major to low
  • Milestone 1.3.2 deleted
  • Keywords jquery.text removed
  • Resolution worksforme deleted

comment:4 Changed 2 years ago by jitter

  • Status changed from reopened to closed
  • Resolution set to duplicate

comment:5 Changed 2 years ago by jitter

Duplicate of #2755.

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.