Dmitri Gaskin on jQuery (2008)

Lobsters Hottest Events

Summary

12-year-old Drupal core developer Dmitri Gaskin demoed core jQuery usage at TechTalk in 2008, including selectors, traversal, DOM manipulation, and CSS operations, emphasizing "write less, do more."

<p><a href="https://lobste.rs/s/67043h/dmitri_gaskin_on_jquery_2008">Comments</a></p>
Original Article
View Cached Full Text

Cached at: 07/27/26, 01:41 AM

TL;DR: 12-year-old Drupal core developer Dmitri Gaskin demonstrated the basics of jQuery at a 2008 TechTalk, including selectors, traversal, DOM manipulation, and CSS manipulation, emphasizing "write less, do more." ## Introduction Hawthorne introduces the young speaker Dmitri Gaskin, a 12-year-old Drupal core developer. Gaskin briefly introduces himself and then dives straight into the jQuery topic. He asks the audience how many can write JavaScript, confirms most can, then skips the basics and goes into jQuery. ## jQuery Basics and the $ Function The core of jQuery is the dollar sign function `$()`. It has three common uses: - **Pass a CSS selector**: e.g., `$('table')` returns table elements. - **Pass an HTML string**: Creates DOM elements (not demonstrated due to time constraints). - **Pass a DOM element**: Directly wraps an existing DOM node. Basic usage demonstration: Gaskin opens a table containing a list of open source projects, types `$('table')` in the console, which returns the table, and hovering highlights it. `$('tr')` returns all table rows. `$('.project')`, `$('.project-name')`, `$('.project-ideas')` select by class. Selecting by ID: `$('#asf')` selects the Apache Software Foundation row. ## Traversal Traversal methods navigate the DOM and return new jQuery objects. - **`.children([expr])`**: Gets all child elements, optionally filtered by an expression. - **`.parent([expr])`**: Gets the direct parent element. - **`.parents([expr])`**: Gets all ancestors that match the expression. - **`.find(expr)`**: Finds descendants matching the expression, similar to `.children(expr)` but deeper scope. - **`.filter(expr)`**: Filters the current selection to elements matching the expression. Can also take a function where `this` refers to the current element, and returning `true` keeps it. - **`.eq(index)`**: Gets the element at the given index (0-based). - **`.not(expr)`**: Excludes elements matching the expression. - **`.add(expr)`**: Adds elements matching the expression to the current selection. - **`.next()`**: Gets the next sibling element. - **`.nextAll()`**: Gets all following siblings. - **`.prev()`**: Gets the previous sibling element. - **`.prevAll()`**: Gets all preceding siblings. - **`.slice(start, end)`**: Similar to array slicing. - **`.siblings()`**: Gets all siblings. - **`.end()`**: Reverts to the previous selection (before a destructive operation like `.filter`). - **`.addBack()`**: Merges the current selection with the previous one. Demo: `$('#adium').next()` gets the next row; `$('#adium').children()` gets its two cells; `$('#adium').prevAll()` gets all previous rows. ## DOM Manipulation - **`.html(val)`**: Sets the innerHTML of an element (unescaped). Without arguments, returns the current HTML. - **`.text(val)`**: Sets the text content (automatically escapes HTML). Without arguments, returns the plain text. - **`.append(content)`**: Appends content to the end. - **`.appendTo(target)`**: Appends the current element to the end of the target. - **`.prepend(content)`**: Inserts content at the beginning. - **`.after(content)`**: Inserts content after the element (as a sibling). - **`.before(content)`**: Inserts content before the element. - **`.wrap(html)`**: Wraps the element with HTML, automatically finding the innermost part. - **`.empty()`**: Empties the element's content (including child nodes and text). - **`.remove([expr])`**: Removes elements from the DOM, optionally filtered by an expression (though using `.filter` first is recommended). Demo: `$('#drupal').html('Drupal')` sets HTML; `.text()` escapes it; `$('#adium').remove()` deletes that row; `$('#wesnoth').empty()` clears content but keeps the element. ## Selectors jQuery supports CSS3 selectors, including: - Basic: `#id`, `.class`, `element`. - Pseudo-classes: `:first`, `:last`, `:even`, `:odd`, `:contains(text)`, `:empty`, `:hidden`, `:visible`. - Relationships: `parent > child` (direct child). - Negation: `:not(expr)` (can be nested). - Attribute selectors: `[attribute]`, `[attribute=value]`, `[attribute!=value]`. Demo: `$('tr:first')` selects the first row; `$('tbody > tr:first')` selects the first row under `tbody`; etc. ## CSS and Style Manipulation - **`.attr(name)`**: Gets an attribute value. To set: `.attr(name, value)` or `.attr(map)` (multiple attributes). - **`.removeAttr(name)`**: Removes an attribute. - **`.val()`**: For form elements, gets or sets the value. - **`.css(name, value)`**: Sets a CSS style. Can also use an object, with camelCase property names (e.g., `backgroundColor`) or quoted hyphenated forms. - **`.addClass(class)`**, **`.removeClass(class)`**, **`.toggleClass(class)`**: Class operations. Demo: `$('#asf').css({backgroundColor: 'green', color: 'orange'})` sets background and text color (text may not work due to `a` element). `$('#asf').height()` returns the height, etc. ## Other Useful Methods - **`.html()`** (without arguments returns the innerHTML) - **`.text()`** (returns plain text) - **`.val()`** (returns the input value) - **`.height()`** (returns the height) These methods return native values, not jQuery objects. The talk briefly mentions plugins and advanced jQuery, but due to time constraints, Gaskin quickly wraps up. The entire presentation demonstrates how jQuery makes JavaScript development more efficient. --- Source: YouTube video (https://www.youtube.com/watch?v=8mwKq7_JlS8)

Similar Articles

@VincentLogic: A widely recognized animation tool in the frontend community, 68K stars are no exaggeration! anime.js – a lightweight but incredibly powerful JavaScript animation engine. Frontend devs, you're in for a treat; it's like the Swiss Army knife for animators: all-rounder, whether it's CSS…

X AI KOLs Timeline

Anime.js is a lightweight yet powerful JavaScript animation engine that supports CSS, SVG, DOM attributes, and JavaScript object animation. It features an intuitive API, timeline system, scroll observer, drag-and-drop, and responsive animations. With 68K stars on GitHub, it's a go-to tool for frontend developers and interaction designers.

@VincentLogic: In the past, when doing frontend work, I used to either hunt around for GIFs or write CSS until my head ached just to create a loading animation. Recently I came across this open-source library math-curve-loaders, which generates animations purely using mathematical formulas. I took a look — rose curves, Lissajous curves, and other mathematical figures produce extremely elegant animations. Pure HT…

X AI KOLs Timeline

Introduces an open-source frontend library called math-curve-loaders that utilizes mathematical formulas (such as rose curves and Lissajous curves) to generate elegant loading animations. It is implemented purely with HTML+CSS, has zero dependencies, and comes with a visual debugging panel that allows real-time parameter adjustments and one-click code copying.

HTML Can Do That

Lobsters Hottest

The article highlights new HTML features like <dialog>, popovers, and grouped <details> that enable dynamic functionality without JavaScript, showcasing advancements in web standards and browser compatibility.

HTML-in-Canvas Demos

Hacker News Top

A collection of CSS and Web UI demos from the Chrome DevRel team, including HTML-in-Canvas demos.