Skip to main content

Bug Tracker

Side navigation

#10451 closed bug (invalid)

Opened October 07, 2011 10:56AM UTC

Closed October 22, 2011 07:57AM UTC

.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:
Description

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

Eg.

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

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

    element.append(otherElement);
}

// 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.

Attachments (0)
Change History (2)

Changed October 07, 2011 01:40PM UTC by timmywil comment:1

component: unfiledmanipulation
owner: → 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.

Changed October 22, 2011 07:57AM UTC by trac-o-bot comment:2

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!