.on() event handling in JavaScript (jQuery-like)
How do I make an .on() event handling in javascript (jquery-like)?
Enables you to handle events in the simple .on(event, function) way that jQuery offers. But then without the rest of jQuery (look ma no jquery!!1!). Just your own JavaScript. :). What is a .on() event handling in javascript (jquery-like)? How do you make a .on() event handling in javascript (jquery-like)? This script and codes were developed by Jelmer on 02 December 2022, Friday.
.on() event handling in JavaScript (jQuery-like) - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>.on() event handling in JavaScript (jQuery-like)</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Click us</h1>
<p>This is a paragraph. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis, fugiat.</p>
<ul>
<li>A list item</li>
<li>Another list item </li>
</ul>
<div class=log></div> <script src="js/index.js"></script>
</body>
</html>
.on() event handling in JavaScript (jQuery-like) - Script Codes CSS Codes
.log { color: blue;
}
.on() event handling in JavaScript (jQuery-like) - Script Codes JS Codes
var doc = document, elements = doc.querySelectorAll('h1, p, li'), log = doc.querySelector('.log');
doc.addEventListener('DOMContentLoaded', function() { elements.on('click', function() { log.innerHTML = this + ' clicked!'; }); log.on('mouseover', function() { this.style.color = (this.style.color == 'blue' ? 'green' : 'blue'); log.innerHTML = 'log div hovered!'; });
}); // DOMContentLoaded
// Replicate the .on() event handling function:
Object.prototype.on = function(event, customFunction) { if( this.length > 0 ) { for( i=0; i<this.length; i++ ) { if ( this[i].addEventListener ) { this[i].addEventListener(event, customFunction, false); } else if ( this[i].attachEvent ) { this[i].attachEvent('on' + event, customFunction); } } } else { if ( this.addEventListener ) { this.addEventListener(event, customFunction, false); } else if ( this.attachEvent ) { this.attachEvent('on' + event, customFunction); } }
}
Developer | Jelmer |
Username | jelmerdemaat |
Uploaded | December 02, 2022 |
Rating | 3 |
Size | 2,514 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Justified divs, attempt 2 | 1,795 Kb |
CSS grid system using justify | 2,626 Kb |
Justified divs, attempt 4 | 1,881 Kb |
Ruler CSS gradient background pattern | 1,964 Kb |
Test current page in Google PageSpeed | 1,909 Kb |
Check comment length to filter unuseful ones | 2,759 Kb |
Get Gist comments using GitHub API | 2,020 Kb |
A pure CSS slideshow | 4,471 Kb |
Replaced content cannot have pseudo elements | 1,515 Kb |
Loading spinner moving bars | 2,025 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Learning canvas drawing | Aurer | 2,204 Kb |
React Recipe Box | Krokodill | 5,347 Kb |
A cube | KyleDavidE | 18,627 Kb |
SVG Text Masking | JMChristensen | 2,141 Kb |
Simple Login Form | JoshBlackwood | 4,418 Kb |
Page Transitions in Backbone | Mikefowler | 3,691 Kb |
Wave Lines | Mikehobizal | 4,023 Kb |
Slick Slider | Wearebold | 5,913 Kb |
Tile Animation Thing | Frxnz | 4,332 Kb |
Twitch Live Channels | Inkblotty | 4,956 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!