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

Aperta
#1,156 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, jquery
Ambito
documentation

Direzione di ricerca

Esamina la pagina della documentazione dell’API jquery all’indirizzo https://api.jquery.com/jquery/ e confronta la sua indicazione sull’uso delle virgolette per "class" con l’esempio JavaScript fornito e i risultati delle versioni dei browser. Verifica se l’indicazione è ancora corretta per le versioni rilevanti, quindi aggiorna la documentazione per indicare chiaramente gli scenari applicabili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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>
Lingua principale
HTML
Stelle
324
Fork
259
Merge medio
1g 30m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jquery/api.jquery.com

Tutte le issue di jquery/api.jquery.com

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.