This is going to be a multi-part Video + article tutorial series on JavaScript DOM. You're reading Part 5
You can read Part 4 here:
...
For further actions, you may consider blocking this person and/or reporting abuse
Good article, looking forward for more.. :)
What if there is only one element with that class name, would it still return an HTML Collection? Good article, btw 🔥
Yes,
document.getElementsByClassName
would still return anHTMLcollection
if there is only one element with that class name.Take the following code snippet.
The console will log:
If you have just a single element with a unique class name, you should prefer
document.querySelector
overdocument.getElementsByClassName
.It's syntax will be:
The output in the console will be:
You can also attach an HTML ID to it and use
document.getElementByID
.@praveenreddy1798
@umamaheswari.v
Got it, thank you Habdul 😊
You are welcome.
@praveenreddy1798
@umamaheswari.v
That's a great answer in detail. thank you🙂
You are welcome. I am glad I could help.
Thank you @Habdul 😊
I think it would still return an HTML Collection
Yeah, even I've the same doubt
Great Article, will we also get to know about querySelector in this series?
Yes, they're coming up😊
Great lesson Tharun
Thank you 🙂
Do you plan on introducing
querySelector
andquerySelectorAll
for getting DOM elements? And maybe how to alias them to$
and$$
respectively?Hi Mohamed,
Yes, they are definitely included as a part of this series. 😊 Thank you for showing interest