Element.append() - 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.append() 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 avril 2018.
- Learn more
- See full compatibility
- Report feedback
La méthode Element.append() ajoute un ensemble d'objets Node ou de chaînes de caractères après le dernier enfant d'Element. Les chaînes de caractères sont insérées comme des nœuds Text.
Voici les différences entre Element.append() et Node.appendChild() :
- Element.append() permet d'ajouter des chaînes de caractères tandis que Node.appendChild() accepte uniquement les objets Node.
- Element.append() n'a pas de valeur de retour alors que Node.appendChild() renvoie l'objet Node ajouté.
- Element.append() permet d'ajouter plusieurs nœuds et chaînes de caractères tandis que Node.appendChild() ne permet d'ajouter qu'un seul nœud.
Dans cet article
- Syntaxe
- Exemples
- Spécifications
- Compatibilité des navigateurs
- Voir aussi
Syntaxe
jsappend(param1); append(param1, param2); append(param1, param2, /* ... ,*/ paramN);Paramètres
param1, …, paramNUn ensemble d'objets Node ou de chaînes de caractères à insérer.
Exceptions
DOMException HierarchyRequestErrorLevée lorsque le nœud ne peut être inséré à l'emplacement indiqué dans la hiérarchie.
Exemples
Ajouter un élément
jslet div = document.createElement("div"); let p = document.createElement("p"); div.append(p); console.log(div.childNodes); // NodeList [ <p> ]Ajouter du texte
jslet div = document.createElement("div"); div.append("Du texte"); console.log(div.textContent); // "Du texte"Ajouter un élément et du texte
jslet div = document.createElement("div"); let p = document.createElement("p"); div.append("Du texte", p); console.log(div.childNodes); // NodeList [ #text "Du texte", <p> ]append() est hors de la portée créée par with
La méthode append() n'est pas disponible dans la portée créée par une instruction with. Voir Symbol.unscopables pour plus d'informations.
jslet div = document.createElement("div"); with (div) { append("toto"); } // ReferenceError: append is not definedSpécifications
| Specification |
|---|
| DOM# ref-for-dom-parentnode-append① |
Compatibilité des navigateurs
Voir aussi
- Element.prepend()
- Node.appendChild()
- Element.after()
- Element.insertAdjacentElement()
- NodeList
Help improve MDN
Cette page vous a-t-elle été utile ? Yes No Learn how to contributeCette page a été modifiée le 3 août 2023 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
- customElementRegistry
- 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 Element Dom Js
-
How To Add A New Element To HTML DOM In JavaScript?
-
JavaScript HTML DOM Elements (Nodes) - W3Schools
-
HTML DOM Element AppendChild() Method - W3Schools
-
eateElement - Référence Web API | MDN
-
How To Add An Element To The DOM? - Arek Nawo
-
How To Insert An Element After Another Element In JavaScript
-
JavaScript Append
-
Create A DOM Element - JavaScript Tutorial
-
Add An Element To The DOM With JavaScript - Html - Stack Overflow
-
.append() | JQuery API Documentation
-
Comparing Methods For Appending And Inserting With JavaScript
-
Adding Elements To The DOM - JavaScript Kit
-
JavaScript Tutorial For Beginners #37 - Adding Elements To The DOM
-
How To Add New Elements To DOM In JQuery - Tutorial Republic
-
Adding A New Element To The DOM With Vanilla JS - Go Make Things
-
How To Set A DOM Element As The First Child | By John Au-Yeung
-
How To Append Dom Element In Javascript Code Example
-
How To Append HTML Code To A Div Using JavaScript - GeeksforGeeks
-
Add DOM Elements - JavaScript Video Tutorial - LinkedIn