You are close ... try this.
var temp2 = "#one";
$(document).ready(function () {
$(temp2).click(function () {
$(this).animate({
opacity: '0.15'
},
"slow");
});
});
here is a working example
Alternatively, you can simply use the class and forget about the variable.
$(document).ready(function () {
$('.animateMe').click(function () {
$(this).animate({
opacity: '0.15'
},
"slow");
});
});
See this working example.
"id", ,
var arr = ["one", "two", "three", "four", "five"];
$(document).ready(function () {
jQuery.each(arr, function () {
var id = '#' + this;
$(id).click(function () {
$(id).animate({
opacity: '0.15'
},
"slow");
});
});
});