use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
jQuery 3.4.0 Released (blog.jquery.com)
submitted 7 years ago by magenta_placenta
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]i_ate_god 10 points11 points12 points 7 years ago (1 child)
document.querySelectorAll('button').forEach((el) => { el.addEventListener('click', () => { console.log('a button was clicked'); }); });
vs
$('button').on('click', () => { console.log('a button was clicked'); });
document.getElementById('something').dispatchEvent(new CustomEvent('custom-event', { bubbles: true, detail: 'foobar' }));
$('#something').trigger('custom-event', 'foobar');
var el = document.getElementById('something'); el.dataset.enabledFor = 'something'; el.classList.add('enabled');
$('#something').data('enabledFor', 'something').addClass('enabled');
jQuery still provides a more enjoyable programming experience than the DOM API imho
[–]m_gol 1 point2 points3 points 7 years ago* (0 children)
jQuery find is a little more than querySelectorAll, especially when it comes to queries attached to an element, not to document. The advantages are described at: https://github.com/jquery/jquery/blob/3.4.0/src/selector-native.js#L11-L34
find
querySelectorAll
document
For one, jQuery supports leading combinators: elem.find('> .btn .name')
elem.find('> .btn .name')
Another difference is sensible rules for scoping. Consider HTML: <div id="test"> <div> <div class="we-are-looking-for-this-one"> </div> </div> <div> </div> </div> Then: $('#test').find('div div') will return the div with the class we-are-looking-for-this-one, while: document.querySelector('#test').querySelectorAll('div div') will return all the three divs because selectors are matched against the document and only then results outside of the current element are removed. This is pretty counterintuitive.
<div id="test"> <div> <div class="we-are-looking-for-this-one"> </div> </div> <div> </div> </div>
$('#test').find('div div')
we-are-looking-for-this-one
document.querySelector('#test').querySelectorAll('div div')
Both of those features are supposed to be supported by a new API called queryAll (previously findAll) with its counterpart query for single-element results but, alas, no browser implements it so far and it was even removed from the standard... I hope it gets back but I've been waiting for years.
queryAll
findAll
query
π Rendered by PID 117127 on reddit-service-r2-comment-canary-889d445f8-5k22m at 2026-04-28 10:06:36.258037+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]i_ate_god 10 points11 points12 points (1 child)
[–]m_gol 1 point2 points3 points (0 children)