I am trying to create a jQuery search that will find the element which has just had a data attribute changed. The search isn’t working. Here is the Javascript (compiled from CoffeeScript):
new_temp_value = "" + (Math.round((new Date()).getTime() / 1000));
console.log("new_temp_value is " + new_temp_value);
$activity_div.data('temp', new_temp_value);
console.log('value of data-temp in $activity_div is now');
console.log($activity_div.data('temp'));
console.log($activity_div.hasClass('activity_div'));
console.log($(".activity_div[data-temp='" + new_temp_value + "']"));
Output
new_temp_value is 1336020404
value of data-temp in $activity_div is now
1336020404
true
[]
What is going wrong?
Did you mean to use
.data('temp', '')or.attr('data-temp', '')? Those are two different things. Try the latter, it will work.