Home > front end >  How can I use querySelectorAll with htmx
How can I use querySelectorAll with htmx

Time:05-27

I am working with htmx which is a fantastic library, I have a little problem that's not very clear on how to solve. htmx uses queryselector to locate elements to swap/update example with hx-swap="...", hx-target="..." how do I do a querySelectorAll. example I have a class bookmark, when a user bookmarks a post, I want to update all the classes with .bookmark

CodePudding user response:

You'd use the attribute selector:

const hxSwap = document.querySelectorAll('[hx-swap]');

CodePudding user response:

So, you can do also like this :

let swapOrTarget = document.querySelectorAll("[hx-swap]") || document.querySelectorAll("[hx-target]");
  • Related