在将DOM元素添加到文档之前操纵DOM元素 [英] Manipulate DOM elements before adding them to the document
本文介绍了在将DOM元素添加到文档之前操纵DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道在将它们附加到DOM之前是否有一个 clean 实现来获取元素。
I was just wondering if there is a clean implementation to getting elements before appending them to the DOM.
示例(w / jQuery ):
Example (w/ jQuery):
var html = "<div class = 'test'><div class = 'innertest'>Hello!</div></div>";
var innerDiv = $(html).find('.innertest');
我觉得它不可能, d喜欢看看是否有任何实施,允许这个 - 因为这将是相当甜蜜的课程和分离。
I feel like its not possible, but I'd like to see if there is any implementation out there that allows for this- because this would be pretty sweet for classes and separation.
编辑:我是想知道这是否可能。我的意思是干净的是没有使用像字符串替换或被黑客入侵的东西。
这不是我做的事情。如果我能做到这一点,我会在我去时创建变量。我有一个情况,我有这个html字符串,我想要找到元素和操纵之前,我把它附加到我的页面。
推荐答案
您是否查看了 DOM DocumentFragments ?
这篇关于在将DOM元素添加到文档之前操纵DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文