Reputation: 405
I want remove a class of images with specific data. I am using:
var end_foto = 'http://somesite.com/image.jpg';
$('img[data-url]="'+end_foto+'"').removeClass('thumb-selecionado');
But it returns:
Uncaught Error: Syntax error, unrecognized expression:img[data-url]="http://somesite.com/image.jpg"
What's wrong?
Thanks
Upvotes: 1
Views: 55
Reputation: 21
You have the selector structured wrong. It should look like this:-
$('img[data-url="'+end_foto+'"]').removeClass('thumb-selecionado');
Upvotes: 2
Reputation: 72299
Need ]
in last like below:-
var end_foto = 'http://somesite.com/image.jpg';
$('img[data-url="'+end_foto+'"]').removeClass('thumb-selecionado');
The selector structure need to be img[data-url="abc"]
Example:-
var end_foto = 'http://somesite.com/image.jpg';
$('img[data-url="'+end_foto+'"]').removeClass('thumb-selecionado');
.thumb-selecionado{
width;50px;
height:50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="http://is5.mzstatic.com/image/thumb/Purple/v4/e0/9d/64/e09d64ec-b4f1-5e55-3599-308e29d5a94d/source/100x100bb.jpg" data-url = "http://somesite.com/image.jpg" class="thumb-selecionado"><br/><br/>
<img src="http://is5.mzstatic.com/image/thumb/Purple/v4/e0/9d/64/e09d64ec-b4f1-5e55-3599-308e29d5a94d/source/100x100bb.jpg" data-url = "http://somesite.com/image1.jpg" class="thumb-selecionado"><br/><br/>
Upvotes: 2