How to get the second match with QuerySelector?

2019-01-24 02:49发布

问题:

The following statement gives me the first element with the class titanic

element = document.querySelector('.titanic');

How would I retrieve the second element with the same class?

回答1:

Use document.querySelectorAll

document.querySelectorAll('.titanic')[1]