This is my first attempt at writing jQuery myself. I'm trying to make it so when I hover on an instance of a name, the background changes to white as well as all the other instances of that name. Every name has a unique data-id that is common to all it's instances.
I think my jQuery goes in err at person = this.data("id");
I'm trying to assign the data attribute of the element hovered over and then change the background of all elements with that data attribute. Not sure if I'm even close.
Errors are as follows:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'data' localhost:60
(anonymous function) localhost:60
jQuery.event.special.(anonymous function).handle jquery.js:3353
jQuery.event.dispatch jquery.js:3062
elemData.handle.eventHandle
<div id="center">
<% @instances.each do |instance| %>
<div class="instance" data-id="<%= instance.person.id %>" style="top:<%=top_helper(instance)%>px; left:<%= left_helper(instance) %>px; width:<%= width_helper(instance) %>px;">
<span><%= instance.person.first_name %>, <%= instance.rank %></span>
</div>
<% end %>
</div>
<script>
$("div#center").ready(function(){
var person
$("div.instance").hover(function(){
person = this.data("id");
$data(person).css("background-color","white");
});
});
</script>