| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | # [ajquery.js](https://git.coolaj86.com/coolaj86/ajquery.js)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 18:46:25 -06:00
										 |  |  | The fastest, most lightweight, fewest dependency jQuery alternative. \ | 
					
						
							|  |  |  | **New**: Now typed, Ai-enhanced, and better than ever! | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 18:48:58 -06:00
										 |  |  | Development Build: 721B (types + comments) \ | 
					
						
							| 
									
										
										
										
											2024-08-29 18:36:30 -06:00
										 |  |  | Production Build: 117B (min + gz) | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 17:56:55 -06:00
										 |  |  | ## Example Usage
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Provides modern, advanced CSS4-compatible query selection: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | console.log("innerText:", $("p:nth-child(2").innerText); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | ## Install
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-07 13:17:58 -06:00
										 |  |  | ### via GitHub
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```bash | 
					
						
							| 
									
										
										
										
											2024-08-29 18:52:16 -06:00
										 |  |  | my_ver="v3.0.3" | 
					
						
							| 
									
										
										
										
											2022-06-07 13:17:58 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | mkdir ./vendor/ | 
					
						
							| 
									
										
										
										
											2024-08-29 17:29:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-07 13:17:58 -06:00
										 |  |  | curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajquery.js" \ | 
					
						
							|  |  |  |     -o ./vendor/ajquery.js | 
					
						
							| 
									
										
										
										
											2024-08-29 17:29:03 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Lighthouse-optimized
 | 
					
						
							|  |  |  | npx -p uglify-js@3 uglifyjs ./vendor/ajquery.js -o ./vendor/ajquery.min.js | 
					
						
							| 
									
										
										
										
											2022-06-07 13:17:58 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							|  |  |  | <script src="/vendor/ajquery.js"></script> | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### via CDN
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | ```html | 
					
						
							| 
									
										
										
										
											2024-08-29 18:52:16 -06:00
										 |  |  | <script src="https://unpkg.com/ajquery@3.0.3/ajquery.min.js"></script> | 
					
						
							| 
									
										
										
										
											2024-08-29 17:29:03 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Bundler-optimized: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							| 
									
										
										
										
											2024-08-29 18:52:16 -06:00
										 |  |  | <script src="https://unpkg.com/ajquery@3.0.3/ajquery.min.cjs"></script> | 
					
						
							| 
									
										
										
										
											2024-08-29 17:29:03 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Tree-shaking-optimized: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							| 
									
										
										
										
											2024-08-29 18:52:16 -06:00
										 |  |  | <script src="https://unpkg.com/ajquery@3.0.3/ajquery.min.mjs"></script> | 
					
						
							| 
									
										
										
										
											2024-08-29 17:29:03 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### via NPM
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```sh | 
					
						
							|  |  |  | npm install --save ajquery@3 | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### CommonJS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | let AJQuery = require("ajquery"); | 
					
						
							|  |  |  | let $ = AJQuery.$; | 
					
						
							|  |  |  | let $$ = AJQuery.$$; | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### ESM
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | import AJQuery from "ajquery"; | 
					
						
							|  |  |  | let $ = AJQuery.$; | 
					
						
							|  |  |  | let $$ = AJQuery.$$; | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## API
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### `$(selector, [rootElement])`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Selects the first matching HTML element only (or `null`): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const body = $("body"); | 
					
						
							|  |  |  | const div1 = $("div", body); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### `$$(selector, [rootElement])`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Selects all matching elements (or an empty `NodeList`): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							| 
									
										
										
										
											2021-07-23 05:03:47 -06:00
										 |  |  | const head = $("head"); | 
					
						
							| 
									
										
										
										
											2021-07-23 04:55:29 -06:00
										 |  |  | const stylesheets = $$('link[rel="stylesheet"]', head).map(console.log); | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-23 05:03:47 -06:00
										 |  |  | ## Benchmarks
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-29 17:34:35 -06:00
										 |  |  |  | 
					
						
							| 
									
										
										
										
											2021-07-23 05:03:47 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-23 04:35:17 -06:00
										 |  |  | ## Compatibility
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Written entirely in modern ECMAScript 3, and directly transpilable into ES5, ES6 | 
					
						
							|  |  |  | and beyond (up to ES11) via Webpack, Babel, Rollup, React Native, and AWS | 
					
						
							|  |  |  | InfiniDash. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Works in [all browsers](https://caniuse.com/?search=queryselector) in living | 
					
						
							|  |  |  | memory. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | See the full | 
					
						
							|  |  |  | [Browser Compatibility Matrix](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement#browser_compatibility) | 
					
						
							|  |  |  | on MDN. |