Element: previousElementSibling-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Die schreibgeschützte Eigenschaft Element.previousElementSibling
gibt das Element
direkt vor dem angegebenen im children
-Listenelement des übergeordneten Elements zurück oder null
, wenn das angegebene Element das erste in der Liste ist.
Wert
Ein Element
-Objekt oder null
.
Beispiele
html
<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>
<li>This is a list item</li>
<li>This is another list item</li>
<div id="div-03">Here is div-03</div>
<script>
let el = document.getElementById("div-03").previousElementSibling;
document.write("<p>Siblings of div-03</p><ol>");
while (el) {
document.write("<li>" + el.nodeName + "</li>");
el = el.previousElementSibling;
}
document.write("</ol>");
</script>
Dieses Beispiel gibt beim Laden der Seite Folgendes aus:
Siblings of div-03 1. LI 2. LI 3. DIV 4. DIV
Spezifikationen
Specification |
---|
DOM # ref-for-dom-nondocumenttypechildnode-previouselementsibling② |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
previousElementSibling |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.