Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  179] [ 3]  / answers: 1 / hits: 60521  / 12 Years ago, tue, october 2, 2012, 12:00:00

I have a script


var firstImg = row.getElementsByTagName('img')[0];

and later


if (x){ firstImg.src='/images/checked.png'; }

I'd like to define that the img should be of class='something'


(Get first img with class='something')


More From » javascript

 Answers
36

Use the



 querySelectorAll('img.classname')[0]


this returns first image with class set to class name. However jQuery is better!!



$('img.classname')

[#82808] Sunday, September 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrianobeds

Total Points: 558
Total Questions: 118
Total Answers: 116

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;