What is the difference between the #
and .
(the dot) in Jquery?
#和之间有什么区别? (点)在Jquery?
For example, I have seen
例如,我见过
$('#divName').show();
and also
并且
$('.divName').append();
in our code base, can someone kindly explain? I am a newbie at Jquery.
在我们的代码库中,有人可以解释一下吗?我是Jquery的新手。
4 个解决方案
#1
6
Although it's a css selector fundamentally here are example jQuery Selectors
虽然它基本上是一个css选择器,但这里是jQuery Selectors的例子
#
is an element ID selector
#是元素ID选择器
.
is a element class selector
。是一个元素类选择器
#2
2
#
relates to id attribute of an element, and selector returns first occurence only. .
relates to class attribute, and returns all elements of the class
#与元素的id属性相关,而selector仅返回第一次出现。 。与class属性有关,并返回该类的所有元素
#3
2
#
is used to find elements by id, whereas .
is used to to elements by class name(s).
#用于按id查找元素,而。用于按类名称的元素。
So $('#divName')
means: find div
with id divName
and $('.divName')
means find all divs with class divName
所以$('#divName')表示:找到id为div div的div和$('。divName')表示找到所有div类divName
You can find description of range of selectors at jQuery API Selectors
您可以在jQuery API选择器中找到选择器范围的描述
#4
1
The hash (#) is a selector based on an id like <div id="myid">
and the dot (.) is a selector based on an class like <div class="somethingClass">
哈希(#)是一个基于像
#1
6
Although it's a css selector fundamentally here are example jQuery Selectors
虽然它基本上是一个css选择器,但这里是jQuery Selectors的例子
#
is an element ID selector
#是元素ID选择器
.
is a element class selector
。是一个元素类选择器
#2
2
#
relates to id attribute of an element, and selector returns first occurence only. .
relates to class attribute, and returns all elements of the class
#与元素的id属性相关,而selector仅返回第一次出现。 。与class属性有关,并返回该类的所有元素
#3
2
#
is used to find elements by id, whereas .
is used to to elements by class name(s).
#用于按id查找元素,而。用于按类名称的元素。
So $('#divName')
means: find div
with id divName
and $('.divName')
means find all divs with class divName
所以$('#divName')表示:找到id为div div的div和$('。divName')表示找到所有div类divName
You can find description of range of selectors at jQuery API Selectors
您可以在jQuery API选择器中找到选择器范围的描述
#4
1
The hash (#) is a selector based on an id like <div id="myid">
and the dot (.) is a selector based on an class like <div class="somethingClass">
哈希(#)是一个基于像