Skip to content

In what scenarios the docs about 'The name "class" must be quoted in the object...' are relevant? #1156

Open
@alex-arriaga

Description

@alex-arriaga

jQuery version: 3.4.1

Hi jQuery docs team!
While I was reformatting some code with an automated tool, I noticed that tool removes the quotes in this kind of code:

// Original code
var $p = $('<p>', {
    "class": "b-info", // I am USING quotes for "class"
    text: "Appended text"
});
// After passing the formatter
var $p = $('<p>', {
    class: 'b-info', // Quotes are removed from "class"
    text: "Appended text"
});

So, I went back to jQuery docs in https://api.jquery.com/jquery/ where it is said:

The name "class" must be quoted in the object since it is a JavaScript reserved word, and "className" cannot be used since it refers to the DOM property, not the attribute.

I was wondering if you have identified scenarios/versions where this is RELEVANT.

I did some tests using this minimal code, in:

  • Google Chrome: OK
  • Safari: OK
  • Firefox: OK
  • MS Edge: OK
  • IE 11: OK
  • IE 10 (Emulation): OK
  • IE 9 (Emulation): OK
  • IE 8 (Emulation): FAILS
  • IE 7 (Emulation): FAILS

So, it seems, this code ONLY fails on IE 8 and older versions of that browser, is that correct?
Thanks in advance.
Best regards.

<!doctype html>
<html lang="en">
<body>
    <h1>jQuery test</h1>

    <p>"Appended text" will be appended. Check your console too!</p>

    <script src="./js/jquery-3.4.1.min.js"></script>
    <script>
    	(function($) {
             var $p = $('<p>', {
                 class: 'b-info', // I am not using quotes for "class"
                 text: 'Appended text'
             });

             $('body').append($p);
    	})(jQuery);
    </script>
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions