I'm designing a web app, a cloud. When I upload a file to the database of the one ID, I show the file in question by screen. Up here without problems, the problem comes to me when I want to perform X action on that file. I have disabled the right click to show a menu with several functions.
The question is, how can I know what file (id) I clicked on right? and then how can I know what menu option I have selected and what file?
I've been stuck here for several days, I hope you can help me.
$(document).ready(function(){
//Ocultamos el menú al cargar la página
$("#menu_derecho").hide();
/* mostramos el menú si hacemos click derecho con el ratón */
$(document).bind("contextmenu", function(e){
$("#menu_derecho").css({'display':'block', 'left':e.pageX, 'top':e.pageY});
return false;
});
//cuando hagamos click, el menú desaparecerá
$(document).click(function(e){
if(e.button == 0){
$("#menu_derecho").css("display", "none");
}
});
//si pulsamos escape, el menú desaparecerá
$(document).keydown(function(e){
if(e.keyCode == 27){
$("#menu_derecho").css("display", "none");
}
});
});
div#menu_derecho ul{
list-style: none;
list-style-type: none;
list-style-position: outside;
}
div#menu_derecho li{
list-style: none;
box-shadow: 0 0 0 0 #800;
}
div#menu_derecho li a:hover{
box-shadow: 250px 0 0 0 #FF7A62 inset;
}
div#menu_derecho li a{
line-height: 30px;
font-size: 16px;
cursor:pointer;
padding: 10px;
color: #FFF;
display: block;
text-decoration: none;
-webkit-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}
div#menu_derecho li a span{
float: right;
padding-top: 7px;
}
div#menu_derecho{
width:170px;
position:absolute;
background: tomato;
border:1px solid #800;
z-index: 999999;
-webkit-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}
<!DOCTYPE html>
<html lang="es" >
<head>
<link rel="stylesheet" href="css/clicderecho.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="js/clicderecho.js"></script>
</head>
<body>
<div id="menu_derecho">
<ul>
<li><a href="#">Copiar</a></li>
<li><a href="#">Compartir</a></li>
<li><a href="#">Descargar</a></li>
</ul>
</div>
<div id="cuerpo">
<ul>
<li><spam class="nom_fic" id="1">Fichero 1</spam></li>
<li><spam class="nom_fic" id="2">Fichero 2</spam></li>
<li><spam class="nom_fic" id="3">Fichero 3</spam></li>
<li><spam class="nom_fic" id="4">Fichero 4</spam></li>
</ul>
</div>
</body>
</html>
I would like the final result to be an alert saying (for example) "You have selected Download on file with id 2"