Bug Tracker

Modify

Ticket #4531 (closed bug: invalid)

Opened 4 years ago

Last modified 14 months ago

$("root", xmlData).append("<node />"); doesn't append anything

Reported by: fishbone Owned by:
Priority: major Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: xml;modification Cc:
Blocking: Blocked by:

Description

if d is xmlData loaded with $.ajax,

doesn't work: $("data", d).append("<entry class='c' />");

works: $("data", d).append($("<entry class='d' />"));

tested with the available jQuery nightly downloaded 2009/04/13

Attachments

main.html Download (819 bytes) - added by fishbone 4 years ago.
test.xml Download (151 bytes) - added by fishbone 4 years ago.

Change History

Changed 4 years ago by fishbone

Changed 4 years ago by fishbone

comment:1 follow-up: ↓ 2 Changed 4 years ago by fishbone

i found a similar problem: when traversing the children, none of the newly added entries will be shown:

function listEntries(target) {

$("data", d).children("entry").each(function() {

$("#entries").append("<p>"+$(this).attr("class")+"</p>");

});

}

comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 4 years ago by fishbone

Replying to fishbone:

i found a similar problem: when traversing the children, none of the newly added entries will be shown:

function listEntries(target) {

$("data", d).children("entry").each(function() {

$("#entries").append("<p>"+$(this).attr("class")+"</p>");

});

}

i noticed that .children() is case-sensitive traversing xml data. if you use .children("ENTRY") instead of .children("entry") it works. nevertheless i think it's a bug

comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 4 years ago by fishbone

it's because XML is case-sensitive. anyways it's a bug, because jQuery converts the string in append() to upper case.

comment:4 in reply to: ↑ 3 Changed 4 years ago by fishbone

sorry for bothering :) it isn't jQuery's bug. I tried it with element.appendChild(), and my lower case node name is converted into upper case

comment:5 in reply to: ↑ description Changed 4 years ago by fishbone

jQuery uses a div element for initializing the DOM nodes of the respective selector. the data is appended in line 2275:

div.innerHTML = wrap[1] + elem + wrap[2];

the innerHTML property does the upper case conversion. This is "recommended" for html but invalid for xml data. a discussion about this "innerHTML" behaviour can be found here:  http://www.developer-x.com/content/innerhtml/

comment:6 Changed 4 years ago by dmethvin

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

All of jQuery's internal parsing treats the string as HTML, *not* XML; I've included links to the doc below. If you want to append unparsed XML content to an XML tree, parse it with an XML parser and pass the nodes to append() et al.

 http://docs.jquery.com/Core/jQuery#htmlownerDocument

 http://docs.jquery.com/Manipulation

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.