Reputation: 27
I have a table which is populated taking data from an array of contacts. I need to pass to the function hover one of each contact data (your image). How could he? Here is the code of the dynamic creation of each row. What would have to put behind tr, to capture it on hover?
for(var i in tbContactos)
{
var contacto = JSON.parse(tbContactos[i]);
$("#tblList tbody").append("<tr alt="+contacto.Imagen+">");
.....
.....
$("#tblList").hover(function(event){
var src = $(this).attr("alt");
............
............
Upvotes: 0
Views: 76
Reputation: 1394
try this:
$("#tblList tbody").append("<tr onMouseOver='test(this)' alt="+contacto.Imagen+">");
function test(row){
//here you will get the entire row.
row.getElementsByTagName("td")//will return an array of columns within the row
}
Upvotes: 0
Reputation: 28513
To attach hover event you can use .on()
, see below code -
$("#tblList tbody").on("mouseenter","tr",function(){
// do stuff for mouse enter event
var trAttr = $(this).attr('alt');
}).on("mouseleave","tr",function(){
// do stuff for mouse leave event
var trAttr = $(this).attr('alt');
});
Upvotes: 1