I have an HTML table with several rows. If you hover on the row then it displays a contextual menu which allows to add or delete the rows.
When you add the row I clone the existing row and add to the table. This works correctly! The problem is when I hover over the new row it shows the menu at the wrong position. The position is related to the row which I originally cloned! It even return the wrong top and left position which is associated with the original row which was cloned.
Any ideas!
Not sure if this is going to help but here is little bit of code:
function addOptionRow(rowToBeAdded,rowId) {
var searchClass = "TBLCONTENTS";
var rows = $("#" + rowId).parent().children("tr");
var rowCount = rows.length;
for(i=0;i<rows.length;i++) {
if ($(rows[i]).attr('class') != searchClass && $(rows[i]).prev().attr('class') == searchClass) {
rowToBeAdded.attr("id", getRandomString());
$(rows[i]).before(rowToBeAdded.clone());
}
}
}
Here is the menu display code:
function OnMouseOver(obj) { // obj is row which is passed in
var top = 0;
var left = 0;
var id = "#" + obj.id;
currTemplateRow = obj.parentElement.parentElement;
var pos = $(id).position();
top = pos.top - 5;
left = pos.left - 5;
$("#menuToolsetTemplate").css(
{ position: "absolute",
top: top + "px",
left: left + "px"
}
).show();
}
I tried to simulate what you are doing and it works fine for me.. Check my jsFiddle DEMO. Onclick on each row it clones that row and appends it to the bottom. JSBin DEMO
As I mentioned in the comment, the obj that is being passed in your function
OnMouseOver(obj)is not the correct row. You code doesn’t tell us where or how this mouse over function is binded to hover(mouseover and mouseout) event.JS:
HTML