在jQuery里替换DOM节点

由 joelhy 于 周一, 06/04/2007 - 21:35 提交。

由于jQuery没有提供一个用来替换指定节点(node)的api,这就需要组合已提供的api来实现该功能。普遍的做法是组合使用remove()和after()或before()。
例子如下:

  1. remove() + after()
    $("#node_to_remove").after(node_to_insert_content).remove();
  2. remove() + before()
    $("#node_to_remove").before(node_to_insert_content).remove();

发表新评论

此内容将保密,不会被其他人看见。
  • 网页地址和电子邮件地址将会被自动转换为链接。
  • 允许的 HTML 标签: <img> <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <coolcode>
  • You can use coolfilter tags in the text, to include code and media

更多格式化选项信息