I have a menu that, when right-clicking, it opens in DIV
. Everything happens inside a tr
(line) of a table
.
My problem is the following , I have a table
with several tr
, and each of them gets a ID
.
And I also have several div
and each one of them gets a ID
equal to tr
.
I need javascript
to open DIV
with the same ID as TR
.
Example:
Right clicking on tr id="1"
to div class="menu_pai" id="1"
opens.
Current code:
document.oncontextmenu = function () {
return false;
};
$("tr").mousedown(function (e) {
// Define a posição do menu
$('.menu_pai').css({
"margin-left": e.clientX,
"margin-top": e.clientY
}).show();
// Exibe o menu
if (e.button === 2) {
$(".menu_pai").show();
} else {
$(".menu_pai").hide();
}
});
.menu_pai{
display: none;
}
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script><tablewidth="100%" border="1" >
<tr id="1">
<td>ID:1</td>
<td>Nome</td>
<td>Idade</td>
</tr>
<tr id="2">
<td>ID:2</td>
<td>Nome</td>
<td>Idade</td>
</tr>
<tr id="3">
<td>ID:3</td>
<td>Nome</td>
<td>Idade</td>
</tr>
</table>
<div class="menu_pai" id="1">
<div class="menu">
link 1
</div>
</div>
<div class="menu_pai" id="2">
<div class="menu">
link 2
</div>
</div>
<div class="menu_pai" id="3">
<div class="menu">
link 3
</div>
</div>