Reputation: 365
Or operator does not work. could you help how to get it right.
$('.iconWrapper span').click(function(e) {
$('#div1').find('img').attr('src', function(index, src) {
if( src =='../../photo/roz1.jpg' || '../../photo/roz2.jpg'){
alert ('ohra');
}else{
alert ('lil');
}
});
Upvotes: 1
Views: 3975
Reputation: 63814
In JavaScript || is used for or. Your if should read something like this:
if( src == '../../photo/roz1.jpg' || src == '../../photo/roz2.jpg'){
You really need to leran the basiscs, checkout these as a starting point:
Upvotes: 2
Reputation: 11912
if( src =='../../photo/roz1.jpg' || src == '../../photo/roz2.jpg'){...
Upvotes: 3
Reputation: 817148
It "does not work" because this operator does not exist in JavaScript (why do you think it does?)
It is ||
, and you have to test the condition explicitly: var == val1 || var == val2
.
var == (val1 || val2)
is doing something different.
if(src =='../../photo/roz1.jpg' || src == '../../photo/roz2.jpg')
Upvotes: 5