empty()
功能
从DOM中删除指定节点的所有子节点。
语法
noder.empty(node)
参数
- node
HTMLElement对象,指定对象HTML元素节点
范例
Example: 移除段落中的所有子节点包括文本。
<!DOCTYPE html> <html> <head> <style> p {background: yellow;} </style> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script> <script> require.config({ baseUrl: "./", packages: [{ name: "skylark", location: "../../../src/skylark" }, ] }); </script> </head> <body> <p> Hello, <span>Person</span> <a href="javascript:;">and person</a> </p> <button>Call empty() on above paragraph</button> <script> require(["skylark/query", "skylark/finder", "skylark/noder"], function(query, finder, noder) { query("button").click(function() { noder.empty(finder.find("p")); }); }); </script> </body> </html>