Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a data attribute value with a space or a certain character

I'm trying to select a data attributes value that has a space or a certain character in it but it doesn't like it very much. Below is the code that I have working for one worded attribute values.

$('div[data-roomtype='+$(this).data('roomtype')+']').animate({opacity:0.1},100);

And I have also put together a very simplified fiddle (http://jsfiddle.net/Tse6k/2/) of what I'm hoping to achieve. Is there an easy solution to this? Any help or advice would be much appreciated.

like image 827
dev Avatar asked Dec 05 '22 13:12

dev


1 Answers

Quote the value in the selector:

// ------------------v -------------------------------v
$('div[data-roomtype="' + $(this).data('roomtype') + '"]'). ...

DEMO: http://jsfiddle.net/Tse6k/3/

like image 96
VisioN Avatar answered Dec 28 '22 11:12

VisioN