polymer中的选择器

原文地址:https://www.polymer-project.org/1.0/docs/devguide/local-dom#dom-api

The following methods and properties are provided.

Adding and removing children:

  • Polymer.dom(parent).appendChild(node)
  • Polymer.dom(parent).insertBefore(node, beforeNode)
  • Polymer.dom(parent).removeChild(node)
  • Polymer.dom.flush()

Calling append/insertBefore adds the node to parent's light DOM. In order to insert/append into the local DOM of a custom element, use a node in the local DOM as a parent (or this.root, which is the root of the local DOM).

Parent and child APIs:

  • Polymer.dom(parent).childNodes
  • Polymer.dom(parent).children
  • Polymer.dom(node).parentNode
  • Polymer.dom(node).firstChild
  • Polymer.dom(node).lastChild
  • Polymer.dom(node).firstElementChild
  • Polymer.dom(node).lastElementChild
  • Polymer.dom(node).previousSibling
  • Polymer.dom(node).nextSibling
  • Polymer.dom(node).textContent
  • Polymer.dom(node).innerHTML

Note: When working with light DOM children, you may want to consider using the distributed children or effective children APIs. See Work with light DOM children for details.

Query selector:

  • Polymer.dom(parent).querySelector(selector)
  • Polymer.dom(parent).querySelectorAll(selector)

Content APIs:

  • Polymer.dom(contentElement).getDistributedNodes()
  • Polymer.dom(node).getDestinationInsertionPoints()

Node mutation APIs:

  • Polymer.dom(node).setAttribute(attribute, value)
  • Polymer.dom(node).removeAttribute(attribute)
  • Polymer.dom(node).classList

Using these node mutation APIs when manipulating children ensures that shady DOM can distribute content elements dynamically. If you change attributes or classes that could affect distribution withoutusing the Polymer.dom API, call distributeContent on the host element to force it to update its distribution.

Work with local DOM

Every Polymer element has a this.root property which is the root of its local DOM tree. You can manipulate the tree using Polymer.dom methods:

// Append to local DOM
var toLocal = document.createElement('div');
Polymer.dom(this.root).appendChild(toLocal);

// Insert to the local DOM
var toInsert = document.createElement('div');
var beforeNode = Polymer.dom(this.root).childNodes[0];
Polymer.dom(this.root).insertBefore(toInsert, beforeNode);

You can use the automatic node finding feature to locate local DOM nodes:

var item = document.createElement('li');
Polymer.dom(this.$.list).appendChild(item);

You can also locate nodes in the local DOM using querySelectorquerySelectorAll, or the $$utility method:

var cancelButton = Polymer.dom(this.root).querySelector('#cancelButton');

// Shorthand for finding a local DOM child by selector
// (equivalent to the above):
this.$$('#cancelButton');

转载于:https://my.oschina.net/u/2391658/blog/1113936

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值