JQuery vs. Native JS Selectors
How do I make an jquery vs. native js selectors?
A playground for testing jQuery Selectors versus their native counterparts. Note that this Pen accompanies my screencast found at http://youtu.be/rbZCR0kCkWk. Feel free to watch and play along.. What is a jquery vs. native js selectors? How do you make a jquery vs. native js selectors? This script and codes were developed by Kyle Foster on 04 September 2022, Sunday.
JQuery vs. Native JS Selectors - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>jQuery vs. Native JS Selectors</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> <!-- Tag -->
<div> <code>div</code>
</div>
<!-- ID -->
<div id="div"> <code>div#div</code>
</div>
<!-- Class -->
<div class="div"> <code>div.div</code>
</div>
<!-- Attribute -->
<div data-tag="div"> <code>div[data-tag="div"]</code>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
JQuery vs. Native JS Selectors - Script Codes CSS Codes
body { background: #DDD; }
div { text-align: center; background: #CCC; width: 400px; padding: 1em; margin: 1em auto 0 auto;
}
JQuery vs. Native JS Selectors - Script Codes JS Codes
// Demo functions
function jqShowMe( elems ) { elems.css( 'background', 'dodgerblue' ); console.log( elems );
}
function jsShowMe( elem ) { elem.style.background = 'dodgerblue'; console.log( elem );
}
function jssShowMe( elems ) { for ( var i = 0; i < elems.length; i++ ) { var elem = elems[ i ]; elem.style.background = 'dodgerblue'; console.log( elem ); }
}
// jQuery Selection
var jqTag = $( 'div' ), jqId = $( 'div#div' ), jqClass = $( 'div.div' ), jqAttr = $( 'div[data-tag="div"]' );
/*jqShowMe( jqTag );*/
/*jqShowMe( jqId );*/
/*jqShowMe( jqClass );*/
/*jqShowMe( jqAttr );*/
// Older Native Selection
var jsTag = document.getElementsByTagName( 'div' ), jsId = document.getElementById( 'div' ), jsClass = document.getElementsByClassName( 'div' );
/*jssShowMe( jsTag );*/
/*jsShowMe( jsId );*/
/*jssShowMe( jsClass );*/
// Newer Native Selection
var qsTag = document.querySelector( 'div' ), qsId = document.querySelector( 'div#div' ), qsClass = document.querySelector( 'div.div' ), qsAttr = document.querySelector( 'div[data-tag="div"]' );
/*jsShowMe( qsTag );*/
/*jsShowMe( qsId );*/
/*jsShowMe( qsClass );*/
/*jsShowMe( qsAttr );*/
var qsaTag = document.querySelectorAll( 'div' ), qsaId = document.querySelectorAll( 'div#div' ), qsaClass = document.querySelectorAll( 'div.div' ), qsaAttr = document.querySelectorAll( 'div[data-tag="div"]' );
/*jssShowMe( qsaTag );*/
/*jssShowMe( qsaId );*/
/*jssShowMe( qsaClass );*/
/*jssShowMe( qsaAttr );*/
Developer | Kyle Foster |
Username | hkfoster |
Uploaded | September 04, 2022 |
Rating | 3 |
Size | 2,261 Kb |
Views | 26,312 |
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 |
Smart Fixed Header | 4,519 Kb |
SVG Optimization Breakdown | 8,022 Kb |
Askew - A Subtle Parallax Banner Plugin | 5,081 Kb |
Vanilla Flavored Hypher | 22,363 Kb |
Ken Burns Banner | 3,817 Kb |
Manipulating SVG With CSS | 3,640 Kb |
Gradual.js | 2,685 Kb |
Cattywompus - A Subtle Parallax Banner Plugin | 4,486 Kb |
Freemason.js | 12,873 Kb |
A Pen by Kyle Foster | 2,404 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 |
Wikipedia Viewer | Codinger | 4,681 Kb |
Pure CSS Dial | Lukewatts | 3,018 Kb |
A Pen by Eka Risyana | Risyana | 3,705 Kb |
Contact | GanNichiHa | 2,514 Kb |
Vue.js Starter | Andymerskin | 1,268 Kb |
Comparison of Roboto Draft vs Roboto | Jxnblk | 2,880 Kb |
Button shaking | SusanneLundblad | 2,227 Kb |
Atom | Bhlaird | 1,932 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
NgEasyModal | Lorenzodianni | 4,159 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!