Is there a way to jslink a <a href> to a Toggle widget (to indicate seen?)

import panel as pn
toggle =pn.widgets.Toggle(value=False)
href = pn.pane.HTML("<a href="https://www.w3schools.com">Visit W3Schools.com!</a>")

if href clicked, toggle.value = True

Using ReactiveHTML it should be possible:

class Link(pn.reactive.ReactiveHTML):
    
    click = param.Integer(default=0)
    
    _template = """<a id="a" target="_blank" onclick="${script('update_click')}" href="https://www.w3schools.com">Visit W3Schools.com!</a>"""
    
    _scripts = {
        "update_click": """
            data.click = data.click+1
            console.log(data.click)
        """
    }
    
    
toggle =pn.widgets.Toggle(value=False)
link = Link()
link.jscallback(args={"toggle": toggle}, click="toggle.active = (source.click>0)")
pn.Column(toggle, link)
1 Like