Reputation: 1302
I need to change double quotes (") to single quotes (') because of restriction on grunt settings. If i change double to single quotes, getting script error.
Can any one please help to change double to single quotes and error free?
$(".custom-item").click(function(e){
e.preventDefault();
$('a[data-slidesjs-item="' + $(this).attr("data-item") + '"]').trigger('click');
});
Complete script have to be within single quotes only. Thanks
Upvotes: 2
Views: 621
Reputation: 2258
This also works fine.
$('.custom-item').click(function(e){
e.preventDefault();
$('a[data-slidesjs-item=' + $(this).attr('data-item') + ']').trigger('click');
});
Fiddle here
Upvotes: 1
Reputation: 34189
You probably had a error because you didn't escape symbols.
In order to use '
as a character in a string, you need to escape it this way \'
to distinguish it from string beginning \ end.
The following characters should be escaped in JavaScript:
\t
\v
\0
\b
\f
\n
\r
\'
\"
\\
What about your case. You should have simply changed all JS quotes to single quotes, and string quote characters to \'
. This code works for me:
$('.custom-item').click(function(e){
e.preventDefault();
$('a[data-slidesjs-item=\'' + $(this).attr('data-item') + '\']').trigger('click');
});
However, at StackOverflow people who ask questions like "do this for me, I couldn't do anything" are usually left without an answer. Consider this next time. You should have posted a code which generates a error. So that we had something to start from.
Upvotes: 2