# Pass template content variable to javascript

**URL:** <https://forum.djangoproject.com/t/pass-template-content-variable-to-javascript/22313>\
**Category:** Templates & Frontend\
**Created:** [July 15, 2023, 4:10pm UTC](https://forum.djangoproject.com/t/pass-template-content-variable-to-javascript/22313 "2023-07-15T16:10:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zejiang](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/zejiang/32/14430_2.png) [@zejiang](https://forum.djangoproject.com/u/zejiang)\
**Post date:** [July 15, 2023, 4:10pm UTC](https://forum.djangoproject.com/t/pass-template-content-variable-to-javascript/22313/1 "2023-07-15T16:10:52Z")

</div>

On a template, I have

```auto
{% trans "Deletion Confirmation" as del_title %}
<a id="deleteSelectedBtn" class="btn">Delete Selected</a>

```

and have javascript code as below

```auto
$(document).ready(function() {
    $('#deleteSelectedBtn').click(function() {
        // How to get value of "del_title" from the template to here?
    });
});

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 15, 2023, 4:22pm UTC](https://forum.djangoproject.com/t/pass-template-content-variable-to-javascript/22313/2 "2023-07-15T16:22:50Z")

</div>

See the [json\_script](https://docs.djangoproject.com/en/4.2/ref/templates/builtins/#json-script) tag for the appropriate way for passing data from Django to a JavaScript script.  
You might want to call that `trans` function in the view to get the value, and then render the value in the json\_script tag.

---

<div class="post-metadata">

**Author:** ![zejiang](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/zejiang/32/14430_2.png) [@zejiang](https://forum.djangoproject.com/u/zejiang)\
**Post date:** [July 15, 2023, 10:07pm UTC](https://forum.djangoproject.com/t/pass-template-content-variable-to-javascript/22313/3 "2023-07-15T22:07:44Z")

</div>

This worked. Thanks Ken!
