assName - Référence Web API | MDN
Maybe your like
- Skip to main content
- Skip to search
Cette page a été traduite à partir de l'anglais par la communauté. Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.
View in English Always switch to English
element.className Baseline Widely availableCette fonctionnalité est bien établie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis juillet 2015.
- Learn more
- See full compatibility
- Report feedback
La propriété className de l'interface Element récupère et définit la valeur de l'attribut class de l'élément spécifié.
Dans cet article
- Syntaxe
- Exemple
- Notes
- Spécifications
- Compatibilité des navigateurs
- Voir aussi
Syntaxe
jsvar cName = elementNodeReference.className; elementNodeReference.className = cName;- cName est une String (chaîne de caractères) représentant la classe (ou les classes séparées par des espaces) de l'élément courant.
Exemple
jslet elm = document.getElementById("item"); if (elm.className === "active") { elm.className = "inactive"; } else { elm.className = "active"; }Notes
Le nom className est utilisé pour cette propriété au lieu de class à cause de conflits éventuels avec le mot-clé « class » dans beaucoup de langages utilisés pour manipuler le DOM.
className peut être une instance de SVGAnimatedString si l'element est un SVGElement. Dans ce cas là, l'usage de className ne fonctionnera pas, il sera donc préférable d'utiliser Element.getAttribute et Element.setAttribute si vous utilisez des élements SVG.
jselm.setAttribute("class", elm.getAttribute("class"));Spécifications
| Specification |
|---|
| DOM# ref-for-dom-element-classname① |
Compatibilité des navigateurs
Voir aussi
- element.classList
Help improve MDN
Cette page vous a-t-elle été utile ? Yes No Learn how to contributeCette page a été modifiée le 7 sept. 2025 par les contributeurs du MDN.
View this page on GitHub • Report a problem with this content Filter sidebar- Référence du DOM
- Element
- Propriétés d'instance
- ariaActiveDescendantElement
- ariaAtomic
- ariaAutoComplete
- ariaBrailleLabel
- ariaBrailleRoleDescription
- ariaBusy
- ariaChecked
- ariaColCount
- ariaColIndex
- ariaColIndexText
- ariaColSpan
- ariaControlsElements
- ariaCurrent
- ariaDescribedByElements
- ariaDescription
- ariaDetailsElements
- ariaDisabled
- ariaErrorMessageElements
- ariaExpanded
- ariaFlowToElements
- ariaHasPopup
- ariaHidden
- ariaInvalid
- ariaKeyShortcuts
- ariaLabel
- ariaLabelledByElements
- ariaLevel
- ariaLive
- ariaModal
- ariaMultiLine
- ariaMultiSelectable
- ariaOrientation
- ariaOwnsElements
- ariaPlaceholder
- ariaPosInSet
- ariaPressed
- ariaReadOnly
- ariaRelevant Non standard
- ariaRequired
- ariaRoleDescription
- ariaRowCount
- ariaRowIndex
- ariaRowIndexText
- ariaRowSpan
- ariaSelected
- ariaSetSize
- ariaSort
- ariaValueMax
- ariaValueMin
- ariaValueNow
- ariaValueText
- assignedSlot
- attributes
- childElementCount
- children
- classList
- className
- clientHeight
- clientLeft
- clientTop
- clientWidth
- currentCSSZoom
- elementTiming Expérimental
- firstElementChild
- id
- innerHTML
- lastElementChild
- localName
- namespaceURI
- nextElementSibling
- outerHTML
- part
- prefix
- previousElementSibling
- role
- scrollHeight
- scrollLeft
- scrollLeftMax Non standard
- scrollTop
- scrollTopMax Non standard
- scrollWidth
- shadowRoot
- slot
- tagName
- Méthodes d'instance
- after()
- animate()
- append()
- ariaNotify() Expérimental Non standard
- attachShadow()
- before()
- checkVisibility()
- closest()
- computedStyleMap()
- getAnimations()
- getAttribute()
- getAttributeNames()
- getAttributeNode()
- getAttributeNodeNS()
- getAttributeNS()
- getBoundingClientRect()
- getClientRects()
- getElementsByClassName()
- getElementsByTagName()
- getElementsByTagNameNS()
- getHTML()
- hasAttribute()
- hasAttributeNS()
- hasAttributes()
- hasPointerCapture()
- insertAdjacentElement()
- insertAdjacentHTML()
- insertAdjacentText()
- matches()
- moveBefore()
- prepend()
- querySelector()
- querySelectorAll()
- releasePointerCapture()
- remove()
- removeAttribute()
- removeAttributeNode()
- removeAttributeNS()
- replaceChildren()
- replaceWith()
- requestFullscreen()
- requestPointerLock()
- scroll()
- scrollBy()
- scrollIntoView()
- scrollIntoViewIfNeeded() Non standard
- scrollTo()
- setAttribute()
- setAttributeNode()
- setAttributeNodeNS()
- setAttributeNS()
- setCapture() Non standard Obsolète
- setHTML()
- setHTMLUnsafe()
- setPointerCapture()
- toggleAttribute()
- Évènements
- afterscriptexecute Non standard Obsolète
- animationcancel
- animationend
- animationiteration
- animationstart
- auxclick
- beforeinput
- beforematch
- beforescriptexecute Non standard Obsolète
- beforexrselect Expérimental
- blur
- click
- compositionend
- compositionstart
- compositionupdate
- contentvisibilityautostatechange
- contextmenu
- copy
- cut
- dblclick
- DOMActivate Obsolète
- DOMMouseScroll Non standard Obsolète
- focus
- focusin
- focusout
- fullscreenchange
- fullscreenerror
- gesturechange Non standard
- gestureend Non standard
- gesturestart Non standard
- gotpointercapture
- input
- keydown
- keypress Obsolète
- keyup
- lostpointercapture
- mousedown
- mouseenter
- mouseleave
- mousemove
- mouseout
- mouseover
- mouseup
- mousewheel Non standard Obsolète
- MozMousePixelScroll Non standard Obsolète
- paste
- pointercancel
- pointerdown
- pointerenter
- pointerleave
- pointermove
- pointerout
- pointerover
- pointerrawupdate
- pointerup
- scroll
- scrollend
- scrollsnapchange Expérimental
- scrollsnapchanging Expérimental
- securitypolicyviolation
- touchcancel
- touchend
- touchmove
- touchstart
- transitioncancel
- transitionend
- transitionrun
- transitionstart
- webkitmouseforcechanged Non standard
- webkitmouseforcedown Non standard
- webkitmouseforceup Non standard
- webkitmouseforcewillbegin Non standard
- wheel
- Héritage
- Node
- EventTarget
- Pages liées à DOM
- AbortController
- AbortSignal
- AbstractRange
- Attr
- CDATASection
- CharacterData
- Comment
- CustomEvent
- DOMError Obsolète
- DOMException
- DOMImplementation
- DOMParser
- DOMTokenList
- Document
- DocumentFragment
- DocumentType
- Event
- EventTarget
- HTMLCollection
- MutationObserver
- MutationRecord
- NamedNodeMap
- Node
- NodeIterator
- NodeList
- ProcessingInstruction
- QuotaExceededError Expérimental
- Range
- ShadowRoot
- StaticRange
- Text
- TreeWalker
- XMLDocument
- XPathEvaluator
- XPathExpression
- XPathResult
- XSLTProcessor
- Guides
- Anatomy of the DOM
- Réflexion des attributs
- Sélection et parcours de l'arbre DOM
- Construire et mettre à jour l'arbre DOM
- Travailler avec des événements
Tag » Add Classname To Element Javascript
-
How To Add A Class Name - W3Schools
-
HTML DOM Element ClassName Property - W3Schools
-
Javascript - How To Add A Class To A Given Element? - Stack Overflow
-
JavaScript Adding A Class Name To The Element - GeeksforGeeks
-
assList - Référence Web API | MDN
-
How To Add A Class To An Element Using JavaScript - Javatpoint
-
How To Add Class Name To The HTML Element Through JavaScript?
-
.addClass() | JQuery API Documentation
-
Add Class To Clicked Element Using JavaScript - Bobbyhadz
-
Add Classname In Javascript Code Example - Code Grepper
-
How To Add A Class Name To An Element With JavaScript?
-
How To Add A Class To A Given Element In JavaScript
-
Create An Element With Classes Using JavaScript | Bobbyhadz
-
Remove And Add Class Names From Elements Using Pure JavaScript