Why donate
API Explorer
DOM Utils

Helping Tree-Shake

You will notice all examples import different parts of Quasar. However, if you need only one specific util method, then you can use ES6 destructuring to help Tree Shaking embed only that method and not all around it.

Example with dom utils:

import { dom } from 'quasar'
const { offset } = dom

// Offset on screen
// { top: 10, left: 100 }

You can also import all of dom utils and use whatever you need like this (but note that your bundle will contain unused methods too):

import { dom } from 'quasar'

// Offset on screen
// { top: 10, left: 100 }


For usage with the UMD build see here.

Offset on screen viewport

import { dom } from 'quasar'
const { offset } = dom

// Offset on screen
// { top: 10, left: 100 }

Get Computed Style

This applies only when DomElement is visible! It returns the computed browser style, so the property you are asking for doesn’t necessary has to be applied within a style attribute.

import { dom } from 'quasar'
const { style } = dom

// Get COMPUTED style (when DomElement is visible!)
// Computed means a DomElement might not have "height" CSS property set,
// but that does not mean it doesn't have a height when it's displayed.
// The following method accesses the computed CSS provided by the browser:
console.log(style(DomElement, 'height'))
// '10px' <<< notice it returns a String ending in 'px'

Get Height / Width

import { dom } from 'quasar'
const { height, width } = dom

// Some aliases of the previous method for "width" and "height" which
// returns Numbers instead of Strings:
// 10 100

Apply CSS Properties in Batch

import { dom } from 'quasar'
const { css } = dom

// Apply a list of CSS properties to a DomNode
css(DomElement, {
  height: '10px',
  display: 'flex'

Execute when DOM is ready

import { dom } from 'quasar'
const { ready } = dom

// Execute a Function when DOM is ready:
ready(function () {
  // ....

Handling event on a DOM event handler

It’s cross-browser.

import { event } from 'quasar'

node.addEventListener('click', evt => {
  // left clicked?
  (Boolean) event.leftClick(evt)

  // middle clicked?
  (Boolean) event.middleClick(evt)

  // right clicked?
  (Boolean) event.rightClick(evt)

  // key in number format
  (Number) event.getEventKey(evt)

  // Mouse wheel distance (in pixels)
  (Object {x, y}) event.getMouseWheelDistance(evt)

  // position on viewport
  // works both for mouse and touch events!
  (Object {top, left}) event.position(evt)

  // get target DOM Element on which mouse or touch
  // event has fired upon
  (DOM Element) event.targetElement(evt)

  // call stopPropagation and preventDefault