PiraTa
PiraTa

Reputation: 485

which image has class, change src JQUERY

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

Answers (3)

Krish R
Krish R

Reputation: 22711

Try this,

$img = $('#sliderInfoBoxImages img');
if($img.hasClass('activeLittle')){
    $img.attr('src', 'some.jpg'); 
}

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

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

Arun P Johny
Arun P Johny

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

Related Questions