Get Relative Cursor Coordinates Using jQuery

Today, We want to share with you Get Relative Cursor Coordinates Using jQuery.In this post we will show you jquery get mouse position without event, hear for jquery get mouse position relative to element we will give you demo and example for implement.In this post, we will learn about get mouse position javascript with an example.

Get Relative Cursor Coordinates Using jQuery

There are the Following The simple About Get Relative Cursor Coordinates Using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop Find Relative Cursor Coordinates Using jQuery, so the some major files and Directory structures for this example is following below.

  • index.html
Read Also:  PHP MySQL Training Banner & Full Course

How to Get Cursor Coordinates Using jQuery

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to Get Cursor Coordinates Using jQuery - Get Relative Cursor Coordinates</title>
<style type="text/css">
    #card{
        width:400px;
        height:300px;
        background: #3d3d3d;
        border: 1px solid #000;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#card").mousemove(function(event){            
            var firsrX = event.pageX - $(this).offset().left;
            var secondY = event.pageY - $(this).offset().top;
            var results = "(" + firsrX + "," + secondY + ")";
            $(".mouse-livecrds").text(results);
        });
    });
</script>
</head>
<body>
<h2>jQuery Find Coordinates of Mouse Pointer</h2>
    <div id="card"></div>
    <p>Your Read Coordinates points of mouse pointer steps with respect area to the HTML Tags DIV card are: <strong class="mouse-livecrds"></strong></p>
</body>
</html>

jQuery Get Relative Mouse Position

simple Example of the Find Cursor Coordinates Using jQuery

$(function() {
$("#card-box").click(function(e) {
  var card = $(this).offset();
  var firsrX = (e.pageX - card.left);
  var secondY = (e.pageY - card.top);
  alert("Your X coordinate: " + firsrX + "  Your Y coordinate: " + secondY);
});
});

Get Relative Cursor Coordinates – Output

Get Relative Cursor Coordinates Using jQuery
Get Relative Cursor Coordinates Using jQuery
Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Remove Item from Array using AngularJS

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Get Relative Cursor Coordinates Using jQuery.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Get the full URL in WordPress
  2. Read Also:  jQuery Foreach Loop ( jQuery.each() ) Example
  3. Read Also:  jQuery AJAX login and registration Form using PHP MySQLi
  4. Read Also:  Laravel Supervisor start stop restart and update database queue
  5. Read Also:  jQuery AJAX Interview Questions and Answers
  6. Read Also:  PHP Laravel Limit String Length (Truncate string) Example
  7. Read Also:  Animation (ngAnimate) using Angular Example
  8. Read Also:  jQuery Foreach Loop ( jQuery.each() ) Example
  9. Read Also:  jQuery AJAX Interview Questions and Answers
  10. Read Also:  jQuery AJAX login and registration Form using PHP MySQLi