Professional Documents
Culture Documents
Dom by Id and by Class
Dom by Id and by Class
elements,
( which is an array-like object.
j
If
a you call the getElementsByClassName() method on the document object, the
vmethod searches for elements with the specified class names in the whole
adocument.
s
c
r
i
p
t
)
However, when you call the getElementsByClassName() method on a specific
element, it returns only matching elements in the subtree of that element.
console.log(data);
Output:
C
o
d["Example 1", "Example 2"]
e
This
C
lo
example calls the getElementsByClassName() method on the document
object,
ad therefore, it searches for the elements with the class heading-secondary
nin
e the entire document.
g
uIn
l this tutorial, you learned how to use the getElementsByClassName() method
aa
to
gn
select elements by one or more class names.
eg
:u
a
Jg
ae
v:
a
S
J
ca
rv
ia
pS
tc
r
(i
jp
at
v
a(
sj
ca
rv
ia
ps
tc
)r
i
p
t
)