推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
just1

如何获取父节点的上一兄弟节点

  •  
  •   just1 · Jan 28, 2016 · 3509 views
    This topic created in 3956 days ago, the information mentioned may be changed or developed.

    找找文档,应该是 this.parentNode.previousSibling
    但是返回的不是对象而是 text...
    怎么获取父节点的上一兄弟节点呢

    8 replies  •  2016-01-29 23:24:20 +08:00
    just1
    just1
    OP
    Jan 28, 2016
    1
    0
    Keita1314
    Keita1314
    Jan 28, 2016❤️1
    2
    previousElementSibling 而不是 previousSibling
    Keita1314
    Keita1314
    Jan 28, 2016❤️1
    3
    Notes
    Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained, for example, using Node.firstChild or Node.previousSibling may refer to a whitespace text node rather than the actual element the author intended to get.

    See Whitespace in the DOM and W3C DOM 3 FAQ: Why are some Text nodes empty? for more information.
    just1
    just1
    OP
    Jan 28, 2016
    4
    @Keita1314 非常感谢
    Roycom
    Roycom
    Jan 28, 2016
    5
    mark
    pysama
    pysama
    Jan 28, 2016❤️1
    6
    @just1
    对于不支持 previousElementSibling 的浏览器。循环获取 previousSibling ,直到其 nodeType 为 1
    westpsk
    westpsk
    Jan 28, 2016
    7
    我只想问为什么要用裴博士作为头像
    just1
    just1
    OP
    Jan 29, 2016 via Android
    8
    @westpsk 当初要传头像,刚好这张图片
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1998 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 12:51 · PVG 20:51 · LAX 04:51 · JFK 07:51
    ♥ Do have faith in what you're doing.