brief.js is an incredibly lightweight (<1k minified and gzipped) and extendable DOM Selection and Event Listener library. brief.js provides an increcibly concise syntax combined with an incredibly intuitive API. I hated writing the same code over and over to handle event listening, so I thought you might be fed up too. You should head over and take a look at our API and Demos so that you can get started!
Multiple Elements
brief.js
// We are going to create a click handler on all divs
// that delegates to all the anchor tags in them
brief('div').on('click', function(event) {
event.preventDefault();
console.log(event);
}, 'a');
Regular JS
// We are going to create a click handler on all divs
// that delegates to all the anchor tags in them
var divs = document.querySelectorAll('div');
for (var i = 0, len = divs.length; i++) {
divs[i].addEventListener('click', function(event) {
if (event.srcElement.tagName.toLowerCase() === 'a') {
event.preventDefault();
console.log(event);
}
}, false);
}
brief.js
// We are going to create a click handler on all divs
// that delegates to all the anchor tags in them
brief('div').on('click', function(event) {
event.preventDefault();
console.log(event);
}, 'a');
Regular JS
// We are going to create a click handler on all divs
// that delegates to all the anchor tags in them
var divs = document.querySelectorAll('div');
for (var i = 0, len = divs.length; i++) {
divs[i].addEventListener('click', function(event) {
if (event.srcElement.tagName.toLowerCase() === 'a') {
event.preventDefault();
console.log(event);
}
}, false);
}