# Code block not executing in embedded version

**URL:** <https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386>\
**Category:** Help\
**Created:** [December 6, 2022, 12:23am UTC](https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386 "2022-12-06T00:23:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomasdegry](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/thomasdegry/32/7268_2.png) [@thomasdegry](https://talk.observablehq.com/u/thomasdegry)\
**Post date:** [December 6, 2022, 12:23am UTC](https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386/1 "2022-12-06T00:23:53Z")

</div>

I have [a notebook](https://observablehq.com/d/a4a9bd19b54698c4) I’m trying to embed, however it’s not fully behaving as expected. The notebook has the following code block that is not firing in the embedded version and I’m trying to understand why:

```auto
{
  changeTab();
}

```

I created a simple Codepen with the embed strategy [here](https://codepen.io/thomasdegry/pen/bGKOKrP). You’ll notice that the console logs nothing in codepen and the `swapTabChoice` call is not made.

At the core I’m trying to understand why this block does not execute, similarly, there’s a console.log statement `console.log('This does not log.');` that does not log so it seems related to top-level cells? And if this is to be expected, how should I approach executing code on what would be the JS equivalent of DOMContentLoaded.

Thanks!

---

<div class="post-metadata">

**Author:** ![Cobus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cobus/32/9670_2.png) [@Cobus](https://talk.observablehq.com/u/Cobus)\
**Post date:** [December 6, 2022, 1:05am UTC](https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386/2 "2022-12-06T01:05:44Z")

</div>

Strange. It works for me, try [https://observablehq.com/embed/a4a9bd19b54698c4?cell=](https://observablehq.com/embed/a4a9bd19b54698c4?cell=)\*

Here is the output I get:

 ![Screenshot 2022-12-05 at 5.04.46 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/6/6f9195f0df297baf62b19f2db162126f9e692a70.png)

---

<div class="post-metadata">

**Author:** ![Cobus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cobus/32/9670_2.png) [@Cobus](https://talk.observablehq.com/u/Cobus)\
**Post date:** [December 6, 2022, 1:13am UTC](https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386/3 "2022-12-06T01:13:03Z")

</div>

Looking at your codepen, I see the issue… you are only embedding one cell… try removing the line:  
`if (name === 'output') {`

---

<div class="post-metadata">

**Author:** ![thomasdegry](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/thomasdegry/32/7268_2.png) [@thomasdegry](https://talk.observablehq.com/u/thomasdegry)\
**Post date:** [December 6, 2022, 2:02am UTC](https://talk.observablehq.com/t/code-block-not-executing-in-embedded-version/7386/4 "2022-12-06T02:02:03Z")

</div>

@Cobus ah good call, appending `else { return true; }` yields the result I was looking for. Thanks so much for that!
