connectseekers.com

Wednesday, 26 April 2017

jQuery To Get Cursor Position in Contenteditable Div

4/26/2017 - By Pranav Singh 0

This article will show you how you can get the Contenteditable div in asp.net using jqery.

So for this article first we will create a new asp.net application and add the below mention jquery library reference into the header of the page.

  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

After this we will add div control on the page.

  X axis -
        <span id="xaxisvalue"></span>
        <br />
        Y axis -
        <span id="yaxisvalue"></span>
        <div id="parentDiv" style="width: 300px; height: 200px; background-color: green;">
        </div>

In above I have taken a div in which I will find the coordinate on mouse moving. Now check the jquery code to get the output.

<script>
        $(document).ready(function () {         
            $("#parentDiv").mousemove(function (e) {
                $("#xaxisvalue").html(e.pageX);
                $("#yaxisvalue").html(e.pageY);
            });
        });
</script>

In above code I have attached the mouseover event to the parent div control. Now have a look of the complete code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>jQuery To Get Cursor Position in Contenteditable Div</title>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script>
        $(document).ready(function () {         
            $("#parentDiv").mousemove(function (e) {
                $("#xaxisvalue").html(e.pageX);
                $("#yaxisvalue").html(e.pageY);
            });
        });</script>
</head>
<body>
    <form id="form1" runat="server">
        X axis -
        <span id="xaxisvalue"></span>
        <br />
        Y axis -
        <span id="yaxisvalue"></span>
        <div id="parentDiv" style="width: 300px; height: 200px; background-color: green;">
        </div>
    </form>
</body>
</html>

Now lets execute the code and check the output.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view




Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top