Search code examples
jinja2htmx

turn a hx-get text into an url


How can I get urls to change to text, the hx-get works fine but with dead text to click:

<span hx-get="/runschedule/{{job['project_id']}}/{{k}}?name={{job['project_name']}}-{{v['name']}}&text=true" \
title="click to schedule {{k}}">{{v['name']}}</span>

like below, but changing to text without following the url:

<a href="/runschedule/{{job['project_id']}}/{{k}}?name={{job['project_name']}}-{{v['name']}}&text=true" \
title="click to schedule {{k}}">{{v['name']}}</a>

Solution

  • You can add a JS event handler that cancels the default behavior of the hyperlink.

    Try this:

    <a href="#" onclick="event.preventDefault();" \
    hx-get="/runschedule/{{job['project_id']}}/{{k}}?name={{job['project_name']}}-{{v['name']}}&text=true" \
    title="click to schedule {{k}}">{{v['name']}}</a>