Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alex-arriaga opened this issue Nov 21, 2019 · 2 comments

Comments

@alex-arriaga
Copy link

alex-arriaga commented Nov 21, 2019

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>
@alex-arriaga alex-arriaga changed the title In what scenarios the docs about 'The name "class" must be quoted in the object...' is relevant? In what scenarios the docs about 'The name "class" must be quoted in the object...' are relevant? Nov 21, 2019
@mgol
Copy link
Member

mgol commented Nov 21, 2019

Yeah, that's not really a useful remark anymore. I'd remove it from the docs. Do you want to submit a PR?

@dmethvin
Copy link
Member

There are also some old tools that complain but at this point nobody should be using really old tools. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants