Reputation: 485
I want to change src for image which has class 'activeLittle'
$('#sliderInfoBoxImages img').hasClass('activeLittle').attr('src', 'some.jpg');
error: Uncaught TypeError: Object #<error> has no method 'attr'
Upvotes: 1
Views: 1386
Reputation: 22711
Try this,
$img = $('#sliderInfoBoxImages img');
if($img.hasClass('activeLittle')){
$img.attr('src', 'some.jpg');
}
Upvotes: 0
Reputation: 67207
The function .hasClass() will return a boolean value. It wont return any elements. By the way you have to use element with class/Id selector
to achieve what you want.
Try,
$('#sliderInfoBoxImages img.activeLittle').attr('src', 'some.jpg');
Upvotes: 0
Reputation: 388316
You need to use the class-selector
$('#sliderInfoBoxImages img.activeLittle').attr('src', 'some.jpg');
.hasClass() returns a boolean result inidicating whether the element has the passed class or not... which does not have the method attr()
so you get the error
Upvotes: 1