Maksim Chemerisuk edited this page Feb 6, 2015 · 10 revisions

There are several frequently asked questions about better-dom:

How to access a native DOM element?

Native element is stored in property [0]:

var body = DOM.find("body");

body[0].addEventListener("click", function() {
    // handle global click using native style
}, false);
Can I use utility functions from Underscore or Lo-dash?

Sure. Note: you don't need to wrap iterated elements (with something like $ in jQuery):

var links = DOM.findAll("a");

_.find(links, function(el) {
  return el.get("title") === "stop";
How to access event object in event listeners?

The event object is not accessible directly, but you can read its properties by specifying an extra array argument in event handlers:

input.on("keydown", ["which", "shiftKey"], (which, shiftKey) {
  // use which to determine key code, and shiftKey
  // to check if the shift key was pressed
Is there a way to find a “DOM” element using a native element?

Sure, just use method DOM.constructor:

// a native bridge example
var foo = DOM.constructor(document.getElementById("foo"));
// a jQuery bridge example
var foo = DOM.constructor($("#foo")[0]);