Bug Tracker

Opened 12 years ago

Closed 12 years ago

#10451 closed bug (invalid)

.html() bug with JQuery objects

Reported by: Jamie Clarke Owned by: Jamie Clarke
Priority: low Milestone: None
Component: manipulation Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:


When using .html() on a JQuery object, all classes added using JQuery (.addClass, .attr("class")) are removed.


var element = $("<div></div>");

for(var i = 0; i < 5; i++) {
    var otherElement = $("span class=\"someClass\">some text</span>");


// For firebug:

console.log(element) // shows all classes whether added with addClass or in the html when creating other element

console.log(element.html()) // shows only class added in html when creating other element (the "someClass" class)

This method was using when creating elements from an AJAX request, the workaround i have used for now (not using .html() and removing the existing element) for anyone with the same issue - but i would be interested to know why this happens.

Change History (2)

comment:1 Changed 12 years ago by Timmy Willison

Component: unfiledmanipulation
Owner: set to Jamie Clarke
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

A couple things I notice are the missing '<' in the html for otherElement and the lack of actually printing the classes.

comment:2 Changed 12 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.