document.querySelector('.selector');
$('.selector');
// selects one node matched given selector
function $(selector, ctx) {
return (ctx || document).querySelector(selector);
}
// selects all nodes matched given selector
function $$(selector, ctx) {
return [].slice.call((ctx || document).querySelectorAll(selector));
}
on
, off
, is
, extend
.is
, matches . extend
, JavaScript Object.assign, on
off
- , , : .myAwesomeLib(document.getElementByID('block'));
appendChild
). .$('.selector')[0].appendChild(node);
$.one
, , , null
// ,
$.one('.selector').appendChild(node);
$.one
, , : ( : $$ $) .import $ from 'balajs';
var $ = require('balajs');
$('.one, two')
$(document.querySelectorAll('.selector'));
$(document.body);
$(element.children);
$(jQuery('.selector'));
$([document.querySelector('.one'), document.querySelector('.two')])
var elements = $('.my-selector', element);
$(function() {
alert('DOM is ready');
});
...
<script src="app.js"></script>
</body>
</html>
var div = $('<div><span class="yeah"></span></div>');
td
tr
, tr
tbody
, option
select
.var cells = $('<td>foo</td><td>bar</td>', 'tr');
$.fn.toggle = function(boolean) {
this.forEach(function(item) {
item.hidden = boolean;
});
};
$('.button').toggle(false); // hides all buttons
<script>
$=function(d,e,c,f,g){c=function(a,b){return new f(a,b)};f=function(a,b){e.push.apply(this,a?a.nodeType||a==window?[a]:""+a===a?/</.test(a)?((g=d.createElement(b||"q")).innerHTML=a,g.children):(b&&c(b)[0]||d).querySelectorAll(a):/f/.test(typeof a)?/c/.test(d.readyState)?a():d.addEventListener("DOMContentLoaded",a):a:e)};c.fn=f.prototype=e;c.one=function(a,b){return c(a,b)[0]||null};return c}(document,[]);
</script>
<script>
$(function() {
alert($('.my-selector').length);
});
</script>
(function(win, $) {
// your code starts here
$(function() {
alert($('.my-selector').length);
});
// your code ends here
})(window, function(d,e,c,f,g){c=function(a,b){return new f(a,b)};f=function(a,b){e.push.apply(this,a?a.nodeType||a==window?[a]:""+a===a?/</.test(a)?((g=d.createElement(b||"q")).innerHTML=a,g.children):(b&&c(b)[0]||d).querySelectorAll(a):/f/.test(typeof a)?/c/.test(d.readyState)?a():d.addEventListener("DOMContentLoaded",a):a:e)};c.fn=f.prototype=e;c.one=function(a,b){return c(a,b)[0]||null};return c}(document,[]));
npm install --save balajs
for(let element of $('.button')) {
console.log(element);
}
$('.button').forEach(function(element) {
console.log(element);
});
$('.my-selector').forEach(function(element) {
element.style.color = 'red';
});
$.one('.my-selector').style.color = 'red';
$('.my-selector').forEach(function(element) {
element.addEventListener('click', function(evt) {
if(this.contains(evt.target.closest('.delegated-selector'))) {
alert('yep!');
}
});
});
$.one('.my-selector').addEventListener('click', function(evt) {
if(this.contains(evt.target.closest('.delegated-selector'))) {
alert('yep!');
}
});
$('.my-selector').forEach(function(element) {
element.remove();
});
$.one('.my-selector').remove();
element.remove
element.closest
.//
$.one('.my-selector').animate([
{transform: 'translate(' + snowLeft + 'px, -100%)'},
{transform: 'translate(' + snowLeft + 'px, ' + window.innerHeight + 'px)'}
], {
duration: 1500,
iterations: 10,
delay: 300
});
fetch('user.json')
.then(function(response) {
return response.json();
})
.then(function(user) {
console.log(user);
})
.catch(alert);
Source: https://habr.com/ru/post/273751/
All Articles