return $.ajax(...)
function request(url, param) {
// ...
return $.ajax({
// ...
});
}
request("/url", param).done(function (data) {
console.log(data.answer);
});
(async () => {
const answer = await request("/url", param);
console.log(answer);
})();
<div>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=10",
"https://picsum.photos/150/150/?image=25",
"https://picsum.photos/150/150/?image=30"
]'>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=5",
"https://picsum.photos/150/150/?image=8",
"https://picsum.photos/150/150/?image=4"
]'>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=2",
"https://picsum.photos/150/150/?image=99",
"https://picsum.photos/150/150/?image=84"
]'>
</div>
<script>
document.querySelectorAll('[data-loop-src]').forEach(image => {
const list = JSON.parse(image.dataset.loopSrc);
(function timer(index = 0) {
setTimeout(() => {
if (list[index]) {
image.src = list[index];
timer(++index);
} else {
setTimeout(timer, 4000);
}
}, 200);
})();
});
</script>
function parseHTML(html) {
const root = document.implementation.createHTMLDocument();
root.body.innerHTML = html
return root.body.children[0];
}
const inputName = parseHTML('<input type="text" name="b_ef1fb2fb5c60353bfdffd48db_71b534c03f" tabindex="-1" value="">').getAttribute('name');
console.log(inputName); //> "b_ef1fb2fb5c60353bfdffd48db_71b534c03f"
const parseHTML = html => {
const root = document.implementation.createHTMLDocument();
root.body.innerHTML = html;
return root.body.children[0];
}
const text = `
<div>
<h1>Text</h1>
<script>
console.log("!");
</script>
</div>
`;
if (parseHTML(text).querySelector('script')) {
alert('isset script')
}
$(".owl-wrapper").css({
transform: `translate3d(${old}px, 0px, 0px)`
});
<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"]')