4
I have a menu that, when right-clicking, it opens in a DIV
. Everything happens within a tr
(line) of a table
.
My problem is this, have a table
with several tr
, and each of them receives a ID
.
And I have also, several div
each of them receives a ID
equal to that of the tr
.
I need the javascript
open the DIV
with the same ID as the TR
.
Example:
Right click on the 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>
<table width="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>
There is a word missing in your question "I have a table with several ," "you get an ID equal to the one of .". Clean it up 'cause I couldn’t understand anything you want.
– DH.
It was because I used hahaha tags, ready to go
– Hugo Borges
change the word from java to javascript please
– Tiago Gomes