jquery / jquery/api.jquery.com
In what scenarios the docs about 'The name "class" must be quoted in the object...' are relevant?
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 325
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the jquery API documentation page at https://api.jquery.com/jquery/ and compare its statement about quoting "class" with the supplied JavaScript example and browser-version results. Check whether the guidance is still accurate for the relevant versions, then update the documentation to state the applicable scenarios clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jquery
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100