'div'和'< div />'之间的jQuery差异何时添加类? [英] jQuery difference between 'div' and '<div/>' when adding class?
问题描述
我正在分析一个插件,但我意识到作者使用:
$('< div />') .addClass( '样品片');
代替以下内容
$( 'DIV')addClass( '样品片');
< div /> $ c是什么意思$ c>,
< a />
......它似乎不是一个有效的html标记。
我似乎无法找到任何解决方案,因为谷歌不允许我在网上搜索运营商.....
div
元素并添加class 样本块
。新创建的div当时不在dom树中,您可能需要将其附加到其他元素。 总结: I was analyzing a plugin but I realize the author uses: instead of the following what is the meaning of I can't seem to find any solution for this as google doesn't allow me from searching operator online..... summarize: 这篇关于'div'和'< div />'之间的jQuery差异何时添加类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! $('div ').addClass('sample-piece'); 添加类
样本块
到所有 div
dom树中的元素。
$('< div />')
会创建一个新的 div
元素。
$('div')
选择所有 div
元素。$('<div/>').addClass('sample-piece');
$('div').addClass('sample-piece');
<div/>
, <a/>
...... it doesn't seem to be a valid html tag.$('<div/>').addClass('sample-piece');
create a new div
element and add class sample-piece
to it. The new created div is not in the dom tree at that time, you may need to append it to some other element.$('div').addClass('sample-piece');
add class sample-piece
to the all the div
elements in the dom tree. $('<div/>')
creates a new div
element.$('div')
selects all the div
elements.