Pass a URL, optionally followed by a space and a selector. Without a selector, the entire response replaces the element's content. With one, jsKjs parses the response in an inert <template> and inserts just the matching nodes — scripts in the response are not executed. The optional callback receives the response text and a status of 'success' or 'error'.
Fragment only
Whole page
View the source for this demo
<div class="row">
<button type="button" id="lf-frag">.load('/api/news.html #headlines')</button>
<button type="button" id="lf-full">.load('/api/news.html')</button>
</div>
<div class="grid g2" style="margin-top:14px">
<div><h4 style="margin:0 0 6px">Fragment only</h4><div id="lf-a" class="out" style="min-height:120px" aria-live="polite"></div></div>
<div><h4 style="margin:0 0 6px">Whole page</h4><div id="lf-b" class="out" style="min-height:120px" aria-live="polite"></div></div>
</div>$('#lf-frag').on('click', () => $('#lf-a').load('/api/news.html #headlines'));
$('#lf-full').on('click', () => $('#lf-b').load('/api/news.html', function (text, status) {
console.log('load finished with status', status);
}));More examples
Refresh a sidebar from the real page
$('#sidebar').load('/account #account-summary');
$('#results').load('/search?q=' + encodeURIComponent(q) + ' .result');API
Fetch HTML into the element. Add a space + selector to insert only a fragment of the response.
Reference: .load() →Migrating
kj-get + kj-target. Fragment selection from a response (htmx's hx-select) is only available through .load() in jsKjs.Related features
$.get, $.post & $.getJSON
One-line GET, POST and JSON requests that return Promises: await $.getJSON(url), $.get(url, data), $.post(url, data) — live examples against real endpoints..
Open →HyperTargets & swaps
Control exactly where server HTML lands with kj-target and how it is inserted with kj-swap — innerHTML, outerHTML, beforebegin, afterbegin, beforeend, afterend, textContent or none..
Open →HyperDeclarative requests
Make GET, POST, PUT, PATCH and DELETE requests straight from HTML with kj-get, kj-post and friends — htmx-style hypermedia with zero JavaScript.
Open →