Monday, May 20, 2024
77
rated 0 times [  80] [ 3]  / answers: 1 / hits: 61368  / 10 Years ago, mon, april 7, 2014, 12:00:00

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?


More From » css-selectors

 Answers
2

Use document.querySelectorAll



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

[#71586] Friday, April 4, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;