Javascript – Get element by tag and class

javascript

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')

Best Answer

Use the

 querySelectorAll('img.classname')[0]

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

$('img.classname')