Skip to content

Any way to target local content like <a href="#fragment">Local Link</a> ? #3414

@JohanMollevikCap

Description

@JohanMollevikCap

I am exploring htmx a bit and am liking what I see. One thing that I had hoped would work but did not was accessing content in the same page.

With pure HTML you can do a local link using Local Link and I was trying the following htmx code to see if I could do the same with htmx. That does not work however and instead of using the local page it goes out and does a GET request to the same URL as the current page. Can this GET request be avoided somehow?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTMLX Test</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/htmx.min.js"
                integrity="sha384-Akqfrbj/HpNVo8k11SXBb6TlBWmXXlYQrCSqEWmyKJe+hDm3Z/B2WVG4smwBkRVm"
                crossorigin="anonymous"></script>
  </head>
  <body>
  <div id="#storage">
        <div id="#test">Test Test</div>
  </div>
  <div id="#content">
        <button hx-get="#storage" hx-select="#test" hx-swap="outerHTML">Replace this with the content under id=test</button>
  </div>
  </body>
</html>

I found this extension that had a different behavior in mind for this syntax
https://github.com/TheDocTrier/hash-select

But this is not what I am trying to do, I am trying to avoid making requests in some cases.

Can this be done in some way, and would it be a good idea if there were some way to make this work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions