# Using cb\_obj from button.js\_on\_click()

**URL:** <https://discourse.bokeh.org/t/using-cb-obj-from-button-js-on-click/8241>\
**Category:** Community Support\
**Tags:** customjs\
**Created:** [August 5, 2021, 7:36am UTC](https://discourse.bokeh.org/t/using-cb-obj-from-button-js-on-click/8241 "2021-08-05T07:36:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dabbatelli](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/dabbatelli/32/3081_2.png) [@dabbatelli](https://discourse.bokeh.org/u/dabbatelli)\
**Post date:** [August 5, 2021, 7:36am UTC](https://discourse.bokeh.org/t/using-cb-obj-from-button-js-on-click/8241/1 "2021-08-05T07:36:20Z")

</div>

Hello,

From reading the doc, my understanding was that the variable “cb\_obj” could be always used inside a CustomJS to reference the model that triggered the callback.

However, this doesn’t seem the case when used on a button.js\_on\_click callback:

```auto
from bokeh.models import Button, CustomJS
from bokeh.plotting import output_notebook, show

b = Button(label="My button")

cb1 = CustomJS(args={'b': b}, code='console.log("cb1: " + b.label)')
cb2 = CustomJS(args={}, code='console.log("cb2: " + cb_obj.label)') # Gives "undefined"
cb3 = CustomJS(code='console.log("cb3: " + cb_obj.label)') # Gives "undefined"

b.js_on_click(cb1)
b.js_on_click(cb2)
b.js_on_click(cb3)

show(b)

```

Am I doing something wrong here, or the “js\_on\_click()” doesn’t support the use of “cb\_obj”?

---

<div class="post-metadata">

**Author:** ![\_jm](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/_/ac91a4/32.png) [@\_jm](https://discourse.bokeh.org/u/_jm)\
**Post date:** [August 5, 2021, 12:13pm UTC](https://discourse.bokeh.org/t/using-cb-obj-from-button-js-on-click/8241/2 "2021-08-05T12:13:09Z")

</div>

@dabbatelli

The following seems to give access to the label in `cb_obj` without the requirement for additional arguments. Verified in bokeh 2.3.3.

`cb3 = CustomJS(code='console.log("cb3: " + cb_obj.origin.label)')`

In my experience, this is definitely different behavior than other JavaScript callbacks such as `js_on_change()`, where you can access properties from the `cb_obj` directly. That said, I do not use the JavaScript callbacks very regularly.

For what it is worth, arrived at this by inspecting the object with `Object.getOwnPropertyNames(cb_obj))` in the JavaScript console to see what was actually in `cb_obj`. So, this is all based on experimentation and nothing in the documentation that I could see, so hopefully the developers can comment on if this is expected or not.

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [November 3, 2021, 12:13pm UTC](https://discourse.bokeh.org/t/using-cb-obj-from-button-js-on-click/8241/3 "2021-11-03T12:13:36Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
