Easy for pros: use pageX & pageY in another function
Hi, im new to javascript and jQuery.
I am currently trying to use jQuerys
var x = e.pageX - this.offsetLeft;
and
var y = e.pageY - this.offsetTop;
in an different function named "navigate()" but its not working. How can i fix this?
Heres the code:
- <link rel="stylesheet" type="text/css" href="scripts/rcmenu/jqcontextmenu.css" />
<script type="text/javascript" src="scripts/JQUERY/jquery.js"></script>
<script type="text/javascript" src="scripts/rcmenu/jqcontextmenu.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.divd').addcontextmenu('rcmenu')
})
function navigate()
{
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
//use of those values (for example redirect)
}
</script>
<ul id="rcmenu" class="jqcontextmenu">
<li><a href="#" onClick="navigate()">Element</a></li>
</ul>
navigate() is fired from a custom context menu as you can see. When I do just "alert("hey"); it works.
Thank you for your time.