limited-potato-46306
01/05/2023, 8:40 PMlimited-potato-46306
01/05/2023, 8:47 PMhundreds-cartoon-20446
01/05/2023, 8:59 PMjolly-waitress-42858
01/06/2023, 3:20 AMcool-match-83608
01/06/2023, 5:29 AMcool-match-83608
01/06/2023, 5:30 AMcool-match-83608
01/06/2023, 5:30 AMsome-solstice-89459
01/06/2023, 10:27 AMsome-solstice-89459
01/06/2023, 10:28 AMsome-solstice-89459
01/06/2023, 10:28 AMmammoth-family-48524
01/06/2023, 12:17 PMsome-solstice-89459
01/06/2023, 12:37 PMsome-solstice-89459
01/06/2023, 12:41 PMrich-television-50179
01/06/2023, 2:10 PMmammoth-family-48524
01/06/2023, 4:58 PMgray-morning-3453
01/06/2023, 6:08 PMfind()
function? And, how is its usage different from javascript's document.querySelector?boundless-vase-80440
01/06/2023, 6:15 PMboundless-vase-80440
01/06/2023, 6:18 PMrich-television-50179
01/06/2023, 6:22 PMhtmx.find()
only to find elements that have htmx attributes, and use JS to find elements that are not using htmx attributes.gray-morning-3453
01/06/2023, 6:27 PMfunction find(eltOrSelector, selector) {
if (selector) {
return eltOrSelector.querySelector(selector);
} else {
return find(getDocument(), eltOrSelector);
}
}
And it seems to use querySelector internally.hundreds-cartoon-20446
01/06/2023, 6:29 PMHX-Location
should behave like the other HX-
headers with respect to history. The ajaxHelper()
function seems to be internal (at least, it's not part of the documented public JS API) so I think it should be ok to change it as Michael has proposed. I also note that redirect requests do not have knowledge of the origin element that triggers the original request, in particular the hx-select
attribute, which can lead to unexpected behaviour if you expect a redirect to "act like following a hx-boost link" as its says in the documentation.
I've created a new branch incorporating Michaels changes and a fix for the origin element issue here: https://github.com/croxton/htmx/tree/refactor/hx-location
Currently all tests are passing. I'm not sure if this will become a PR at this point, just putting it out there for discussion for now.
The other issue that @hundreds-camera-24900 encountered (callback passed in the header) is harder to solve. It's not possible to pass a function in the header json (and using eval()
or similar is dangerous), but I guess you could reference a method of a global object and test if it exists before calling it.
Any thoughts welcome.gray-morning-3453
01/06/2023, 6:40 PMBoth the find() function in htmx and the querySelector() function in JavaScript are used to select elements from the DOM (Document Object Model). However, there are some key differences between the two functions:
The find() function is specific to htmx, while the querySelector() function is a standard DOM function that is supported by all modern browsers.
The find() function is used to select elements within an htmx element, while the querySelector() function is used to select elements from the entire document.
The find() function supports additional features, such as the ability to filter elements by attribute and the ability to select elements within a specific context, while the querySelector() function only allows for selection based on a CSS selector.
The find() function returns an htmx element, which can be used to perform htmx actions, while the querySelector() function returns a standard DOM element, which can be used to perform standard DOM actions.
Overall, the find() function can be a useful tool for working with htmx, while the querySelector() function is a more general-purpose tool for selecting elements from the DOM.
What do you think about this answer?ripe-action-67367
01/06/2023, 6:48 PMripe-action-67367
01/06/2023, 6:49 PMripe-action-67367
01/06/2023, 6:51 PMripe-action-67367
01/06/2023, 6:53 PMgray-morning-3453
01/06/2023, 7:01 PMcurved-processor-1223
01/06/2023, 7:13 PMripe-action-67367
01/06/2023, 7:17 PM