const textfields = $('input[type=text]'); // jQuery
A similar query can also be performed by using the document’s [[https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector|querySelector]] method:
const textfields = document.querySelector("input[type=text]");
Alternative, if only results in a branch of the DOM tree are wanted, the same method also exists for the [[https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement|HTMLElement]]:
const search = document.getElementById('search');
const field = search.querySelector("input[type=text]");
Note that performance-wise, the HTMLElement’s ''querySelector'' brings no advantage, as the method works by first collecting all matches in the document and then filtering them down.
==== HTML Parser ====
jQuery’s ''%%$()%%'' function is also used to parse HTML code into DOM elements, as in the following code:
$('Hello world!
').appendTo('body'); // jQuery
The same can be achieved in plain JavaScript as follows:
const parser = new DOMParser();
const p = parser.parseFromString('Hello world!
', 'application/xml');
document.body.appendChild(p);
Or in jMini:
document.body.appendNew('p').setText('Hello world!'); // jMini
In some situations, the [[toolbox:element:sethtml:index|.setHtml()]] method may be more convenient:
const p = document.getElementById('note');
p.setHtml('Hello world!'); // jMini
==== Document ready event handler ====
Last but not least, the ''%%$()%%'' function in jQuery can also be used to attach a callback function to the ''DOMContentLoaded'' event of the document:
$(function() { // jQuery
…
});
The same can be achieved in jMini in a sightly more verbose, but also much more legible form, using the [[toolbox:event:onready:index|onReady]] method:
document.onReady(function() { // jMini
…
});