I was analyzing a plugin but I realize the author uses:

$('<div/>').addClass('sample-piece');

instead of the following

$('div').addClass('sample-piece');

what is the meaning of <div/>, <a/>...... it doesn't seem to be a valid html tag.

I can't seem to find any solution for this as google doesn't allow me from searching operator online.....

有帮助吗?

解决方案

$('<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.

summarize:

$('<div/>') creates a new div element.

$('div') selects all the div elements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top