Skip to main content

Bug Tracker

Side navigation

#9150 closed bug (invalid)

Opened May 06, 2011 03:55PM UTC

Closed May 06, 2011 04:20PM UTC

Last modified September 26, 2012 11:45AM UTC

Setting className property on new elements does not assign to class attribute

Reported by: patrick.deluxe@gmail.com Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.6
Keywords: Cc:
Blocked by: Blocking:
Description

In v. 1.6:

Input: $('<div/>', { className: 'foo' })

Output: [<div classname=​"foo">​</div>​]

In v. 1.5:

Input: $('<div/>', { className: 'foo' })

Output: [<div class=​"foo">​</div>​]

This is either a regression or an undocumented API compatibility breakage. Which is it?

Attachments (0)
Change History (15)

Changed May 06, 2011 04:20PM UTC by timmywil comment:1

component: unfiledattributes
priority: undecidedlow
resolution: → invalid
status: newclosed

That was never supported and was coincidental that it worked. The attribute to set is class, not className.

Changed May 13, 2011 09:06PM UTC by anonymous comment:2

Wow... It took me a while to find out what caused my code to become totally non-functional after upgrading to 1.6.1.

WHY do you stop supporting the className attribute as a substitute for the class attribute??? Doesn't pure javascript support - and encourage - this substibution, and is the reason not that 'class' is a reserved word???

You can't imagine the quantity of code that will need to be corrected for apparently absolutely no reason.

Changed May 22, 2011 04:21AM UTC by dmethvin comment:3

#9380 is a duplicate of this ticket.

Changed May 22, 2011 04:11PM UTC by uipoet comment:4

At the very least, jQuery should document that this change occurred. There are many tutorials and plugins out there using this unsupported style. With my particular code, I went from a fully working site to a blank page and no errors in the console when I switched to jQuery 1.6!

Changed May 22, 2011 06:29PM UTC by rwaldron comment:5

Drop the jQuery.attrHooks.className code into your plugin modules code:

http://jsfiddle.net/rwaldron/8HBwH/

This will return your code to working order while allowing you to migrate & upgrade painlessly.

Changed May 26, 2011 06:29PM UTC by anonymous comment:6

In any normal release, if this bug were filed the jQuery team would probably have release-noted this as an issue. But this release was so flawed that I suspect that, while operating in "damage control" mode, this issue was buried for political reasons rather than highlighted for engineering ones.

Changed May 26, 2011 06:42PM UTC by timmywil comment:7

This bug is invalid. Passing invalid arguments to attr and having it work was coincidental and subject to change. className is not an attribute, but a property.

Regardless, this would work as well:

http://jsfiddle.net/timmywil/8HBwH/2/

Changed May 26, 2011 07:44PM UTC by rwaldron comment:8

Yours in solidarity:

timmywil +9001

Changed June 09, 2011 04:27PM UTC by anonymous comment:9

This is a huge ooops in 1.6.1. So much code is broken now. People do this all the time:

var th = $('<th>', {
className: 'grouper',
"gsize": gsize,
"glow": glow,
"ghigh": ghigh
}).insertAfter('#advSearch tr th:eq(' + insertWhere + ')');

because class is a reserved word!

Changed June 11, 2011 07:41PM UTC by dmethvin comment:10

I've update the docs to clarify. The current behavior is correct since the name passed to .attr() should be "class" and not className which is the *property* name.

Changed August 16, 2011 11:22AM UTC by anonymous comment:11

Problem is: if you change className to class it dont work in IE 9.

Changed August 16, 2011 02:02PM UTC by rwaldron comment:12

If you put "class" in quotes it shouldn't be a problem. Otherwise, please provide a reduced test case that illustrates the issue in IE9

Changed February 22, 2012 12:34PM UTC by anonymous comment:13

It doesn't work in IE8 even with quotes!

I try this case with yoxview plugin and jQuery 1.7.1 and don't work!

Please, do something! Not say: it's work when it not work!

Changed August 21, 2012 06:10AM UTC by anonymous comment:14

For yoxview, a workaround is to manually change occurrences like

 panelData.element = $("<div>", {
    className: "class_name"
 });

with

 panelData.element = $("<div>", {
 }).addClass(mediaPanelClass);

in the jquery.yoxview-xxx.js file.

Changed September 26, 2012 11:45AM UTC by anonymous comment:15

I've change:

                    if (media.html)
                    {
                        panelData.element = $("<div>", {
                                className: mediaPanelClass
                            });

to:

                    if (media.html)
                    {
                        panelData.element = $("<div>", {
                          }).addClass(mediaPanelClass);

for jquery.yoxview-2.21.js and does not working.