var result = {};
deferredParallel([1, 2, 3, 4, 5], function (id) {
return $.ajax({
url: urlToCreated + '/' + id,
method: 'GET',
dataType: 'json',
data: {
skip: skip,
limit: 100000
},
success: function (data) {
result[id] = data;
}
});
}).done(function () {
console.log(result);
});
function deferredParallel(items, callback) {
var deferreds = [];
for (var i = 0; i < items.length; i++) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferreds.push(deferred);
}
}
return $.when.apply(null, deferreds);
}
var result = [];
deferredParallel([1, 2, 3, 4, 5], function (item) {
return $.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/' + item,
method: 'GET',
dataType: 'json',
success: function (data) {
result.push(data);
}
});
}).done(function () {
console.log(result);
});
function deferredParallel(items, callback) {
var deferreds = [];
for (var i = 0; i < items.length; i++) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferreds.push(deferred);
}
}
return $.when.apply(null, deferreds);
}
var result = [];
deferredQueue([1, 2, 3, 4, 5], function (item) {
return $.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/' + item,
method: 'GET',
dataType: 'json',
success: function (data) {
result.push(data);
}
});
}).done(function () {
console.log(result);
});
function deferredQueue(items, callback) {
var ready = $.Deferred();
;(function fire (i) {
var deferred = callback(items[i], i, items);
if (typeof deferred === 'object' && deferred.done && deferred.fail) {
deferred.done(function () {
items[i + 1] ? fire(++i) : ready.resolve();
});
}
}(0));
return ready;
}
$(".owl-wrapper").css({
transform: `translate3d(${old}px, 0px, 0px)`
});
const raw = '<div class="test" data-status="false"></div>';
const $html = parseHTML(raw);
console.log($html.getAttribute('data-status')); //> "false"
function parseHTML(html) {
const root = document.implementation.createHTMLDocument();
root.body.innerHTML = html;
return root.body.children[0];
}
class Hash {
static encode(content) {
return btoa(unescape(encodeURIComponent(content)));
}
static decode(content) {
return decodeURIComponent(escape(atob(content)));
}
}
const encode = Hash.encode(JSON.stringify([6, 1.5, 23, 34, 'зелёный']));
console.log(encode);
const decode = Hash.decode(encode);
console.log(JSON.parse(decode));
<table>
<thead>
<th>id</th>
<th>name</th>
<th>last</th>
<th>comment</th>
</thead>
<tbody id="container"></tbody>
</table>
const array = [{
id: "Uno",
name: "First point",
last: "Last",
com: "Comment one"
},
{
id: "Dos",
name: "Two point",
last: "Last",
com: "Comment Two"
},
{
id: "Tres",
name: "Three point",
last: "Last",
com: "Comment Three"
},
{
id: "Cuatro",
name: "Four point",
last: "Last",
com: "Comment Four"
}];
document.getElementById('container').innerHTML = tableInner(array);
function tableInner(data) {
let html = '';
data.forEach(item => (html += templateTableRow(item)));
return html;
}
function templateTableRow(data) {
return `
<tr>
<td>${data.id}</td>
<td>${data.name}</td>
<td>${data.last}</td>
<td>${data.com}</td>
</tr>
`;
}
for (let i = 1; i <= 10; i++) {
$(`.year-${i}`).click(() => fullpage_api.moveTo(i + 1));
}
<style>
.tabs-content:not(:first-child) {
display: none;
}
</style>
<div class="tabs">
<div class="tabs-button-container">
<button type="button" class="tabs-button" data-id="1">Параграф 1</button>
<button type="button" class="tabs-button" data-id="2">Параграф 2</button>
<button type="button" class="tabs-button" data-id="3">Картинка</button>
</div>
<div class="tabs-content-container">
<div class="tabs-content" data-id="1">
1. Lorem ipsum dolor sit amet.
</div>
<div class="tabs-content" data-id="2">
2. Lorem ipsum dolor sit amet.
</div>
<div class="tabs-content" data-id="3">
<img src="https://avatars.mds.yandex.net/get-pdb/1220848/0b4c6812-c360-49c3-9266-d0fa010e493f/s1200" width="350">
</div>
</div>
</div>
<script>
(function ($) {
'use strict';
$('.tabs-button').on('click touch', function (event) {
event.preventDefault();
var id = $(this).data('id');
$('.tabs-content').hide();
$('.tabs-content[data-id="' + id + '"]').fadeIn();
});
}(jQuery));
</script>
(function () {
'use strict';
var original = {
open: XMLHttpRequest.prototype.open,
send: XMLHttpRequest.prototype.send
};
XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
console.log(url);
return original.open.call(this, method, url, async, user, password);
};
XMLHttpRequest.prototype.send = function (data) {
console.log(data);
return original.send.call(this, data);
};
}());
нужно обратиться к определенному элементу по классу ".jq_item_remove " (к примеру) с определенным значением data без перезагрузки страницы.
$('.jq_item_remove[data-key="value"]')
image
jQuery элемент, объект. Вы конкатите строку imageSortable
с обектом. imageSortable
строка и у строки нету метода appendTo
.var image = '<img src="'+ event.target.result +'" width="50" height="50" style="margin-left: 10px; margin-bottom: 8px">';
var imageSortable = '<li class="ui-state-default">' + image + '</li>';
placeToInsertImagePreview.append(imageSortable);
(function () {
'use strict';
var selector = {
$button: document.querySelector('a'),
$one: document.querySelector('.one'),
$two: document.querySelector('.two')
};
selector.$button.addEventListener('click', function (event) {
event.preventDefault();
if (isHidden(selector.$one)) {
changeDisplay(selector.$one, 'block');
changeDisplay(selector.$two, 'none');
} else {
changeDisplay(selector.$one, 'none');
changeDisplay(selector.$two, 'block');
}
});
function changeDisplay($node, value) {
$node.style.display = value;
return $node;
}
function isHidden($node) {
return window.getComputedStyle($node).display === 'none';
}
}());