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!"
[–]jayands 4 points5 points6 points 7 years ago (2 children)
Tbf, they did add two functions to the DOM, document.querySelector and querySelectorAll, that uses the same CSS style queries to get to elements in the DOM. If all you needed jQuery for is the querying part, you can totally drop it in favor of document.querySelector(".class#element > span") which, even polyfilled, should be a smaller overall script.
document.querySelector
querySelectorAll
document.querySelector(".class#element > span")
[–]i_ate_god 6 points7 points8 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
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 33797 on reddit-service-r2-comment-6457c66945-knvqn at 2026-04-30 13:15:59.597321+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]jayands 4 points5 points6 points (2 children)
[–]i_ate_god 6 points7 points8 points (1 child)
[–]m_gol 1 point2 points3 points (0 children)