Javatpoint Logo
Javatpoint Logo

Javascript offsetX property

Javascript 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.

Examples

The 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.

Javascript offsetX property

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.

Javascript offsetX property

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.

Javascript offsetX property

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.

Javascript offsetX property

Web Browsers Supported

The given browsers and its version supported the offset property.

  • Opera 12.1 or later
  • Internet Explorer version 9 and up
  • Google Chrome version 1 and up
  • Edge 12 or higher
  • Firefox
  • Apple Safari version 1 and above

Conclusion

The 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.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA