Specify that .data and .attr can't be mixed

Aperta
#1,143 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
45/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
jquery
Ambito
documentation

Direzione di ricerca

Inizia dalla documentazione di .attr e .data e rivedi l’esempio CodePen collegato per confermare il comportamento descritto. Il lavoro è completato quando la documentazione pertinente avverte chiaramente che mescolare .data e .attr può produrre risultati imprevisti, perché non aggiornano lo stesso stato del DOM.

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

Descrizione

I found out the hard way that you can't mix usage of .data and .attr.

The .data documentation clearly states that it doesn't change the DOM upon setting a value.

However, the .attr documentation talks at length about the difference between it and prop, but does not state that it doesn't change the dataset of the DOM node, as demonstrated here: https://codepen.io/cosmo0/pen/YzKVBPp?editors=0011

So your code has to be very strict about using either .data or .attr, because mixing both can result in unexpected behavior, at least when you don't know how jQuery works.

I understand it's by-design, but maybe a warning in the .attr documentation (and/or the .data?) would help people to not fall for this trap?

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.