Class name:
var x = document.getElementsByClassName("intro");
CSS selector:
var x = document.querySelectorAll("p.intro");
I'm confused is there is any difference or both are same?
Class name:
var x = document.getElementsByClassName("intro");
CSS selector:
var x = document.querySelectorAll("p.intro");
I'm confused is there is any difference or both are same?
document.getElementsByClassName("intro");
returns an array of html elements
document.querySelectorAll("p.intro");
returns an array of nodes
And the difference between elements and nodes is explained here
Class names are one type of CSS Selectors, we also have elements, ids, pseudo selectors and these can be combined in different ways. See a full list https://www.w3schools.com/cssref/css_selectors.asp
document.getElementsByClassName
would only let you input class selectors
document.querySelectorAll
lets you use all and combine them in various ways just as you did with your p.intro
As pointed out, you can fine-tune the class selection by using multiple class names if that element possesses all.