问题描述
文档中有许多Div
$ < div class =sample/>
..
< div class =sample/>
..
< div class =sample/>
..
< div id =samplediv>
< div class =sample>
< div>
< / div>
我的问题是通过类示例找到div并处理该div的一些属性。所以我想用class =sample来获得Div吗?
通过类名使用函数: getElementsByClassName(sample)
它可用于任何元素,包括 document
(如 document.getElementsByClassName
)。问题是,旧的浏览器不支持这一点。相反,您可以使用jQuery来做同样的事情:
$(。sample)
希望这有助于您!
Hi How can I get hold of elements within a Div that uses a class say "sample"?
There are many Div's in the document
<div class="sample"/>
..
<div class="sample"/>
..
<div class="sample"/>
..
<div id = "samplediv">
<div class="sample">
<div>
</div>
My question was to find the div with class sample and manipulate some properties of this div. So I want to get hold of the Div with class = "sample"?
In most modern browsers, you can get objects by class name using the function:
getElementsByClassName("sample")
This is available on any element, including document
(as in document.getElementsByClassName
). Problem is, older browsers don't support this. Instead, you can use jQuery to do the same thing:
$(".sample")
Hope this helps!
这篇关于具有Div的元素具有特定的类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!