Javascript offsetX propertyJavascript offset property displays the x-coordinate or width of the specific element. The read-only MouseEvent offsetX attribute returns the x-coordinate of the mouse cursor for the target element. We can add the event function on the div tag, web page, or other elements to show x-coordination. Syntax The following syntax works for the offsetX function. We can get the horizontal value of the specific element. Return Value It gives back a number that, in pixels, indicates the mouse pointer's horizontal coordinate. ExamplesThe following examples show the x-coordinate of the given elements. Example1 The following example displays the width or x-coordinate of the paragraph <p> elements. These coordinates work with the function and mouse cursor. The property displays the width up to the mouse cursor on the element. Output The image displays the x-coordinates of the paragraph <p> elements. Example2 The following example displays the x-coordinate of the paragraph elements. This property works with the function and mouse cursor. The property displays the width up to the mouse cursor on the alert box. Output The image displays the x-coordinates of the paragraph <p> elements. Example3 The following example displays the x-coordinate of the body elements. This property works with the function and mouse cursor. The property displays the width up to the mouse cursor on the alert box. Output The image displays the x-coordinates of the paragraph <p> elements. Example4 The following example displays the width or x-coordinate of the entire web page. These coordinates work with the function and mouse cursor. The property displays the width up to the mouse cursor of the <html> tag. Output The image displays the x-coordinates of the paragraph <p> elements. Web Browsers SupportedThe given browsers and its version supported the offset property.
ConclusionThe offsetX property helps get the specific elements' width or x-coordinates. It helps users and developers to get responsive functions. It worked to get the exact width from the initial to the mouse cursor. Next TopicJavascript offsetY property |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India