# Call ConnectedCallback only once

**URL:** <https://forum.wixstudio.com/t/call-connectedcallback-only-once/1831>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 11, 2023, 3:40pm UTC](https://forum.wixstudio.com/t/call-connectedcallback-only-once/1831 "2023-04-11T15:40:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlknueller-3](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/karlknueller-3/32/36772_2.png) [@karlknueller-3](https://forum.wixstudio.com/u/karlknueller-3)\
**Post date:** [April 11, 2023, 3:40pm UTC](https://forum.wixstudio.com/t/call-connectedcallback-only-once/1831/1 "2023-04-11T15:40:33Z")

</div>

My question is pretty simple: I have a customElement that dynamically adds information to a table. This, of course, triggers the connectedCallback function.  
However, I want connectedCallback to be called only once (at the beginning), afterwards, I don’t want it to run any code/to not be called. I tried to define a variable “var delimiter = 0” to do this workaround:

```javascript
if(delimiter === 0) {
      //Do connectedCallback stuff
      delimiter = delimiter + 1;
      alert('in delimiter range');
}

```

As you can see, delimiter, which is 0 at the beginning, should increment to 1 after the first execution, thus not entering the next time because of the if clause. That doesn’t work though. Any other ideas or maybe even ways to eliminate connectedCallback completely after the first time? Or, if that is easier, I would also be open for a way to fully strike connectedCallback out.  
Thank you!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 11, 2023, 4:10pm UTC](https://forum.wixstudio.com/t/call-connectedcallback-only-once/1831/2 "2023-04-11T16:10:52Z")

</div>

Question:

- What is a connected-Callback for you ?
- In which part of your CODE, do you need it?

```javascript
if(delimiter === 0) {      
    delimiter = delimiter + 1; alert('in delimiter range');}
else { . . . . }

```

As you can see, delimiter, which is 0 at the beginning,

You never defined your delimiter explicitly…

```javascript
let delimiter = 0;

```

```javascript
$w.onReady(()=>{
    let delimiter = 0;
    if(delimiter === 0) {      
        delimiter++;
        console.log('In delimiter range!!');}
    else {
        console.log('Out of delimiter-range, access not possible!');}
});

```

Looks more like an ordinary IF-ELSE-CONDITION.

```javascript
$w.onReady(()=>{
    let delimiter = 0;
    if(delimiter === 0) {start_Function1();}
    else {start_Function2();}
});

function start_Function1() {
    console.log('In delimiter range!!');
    delimiter++;
}

function start_Function2() {
    console.log('Out of delimiter-range, access not possible!');} 
}

```

---

<div class="post-metadata">

**Author:** ![karlknueller-3](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/karlknueller-3/32/36772_2.png) [@karlknueller-3](https://forum.wixstudio.com/u/karlknueller-3)\
**Post date:** [April 11, 2023, 4:21pm UTC](https://forum.wixstudio.com/t/call-connectedcallback-only-once/1831/3 "2023-04-11T16:21:21Z")

</div>

I am deeply sorry, I forgot to mention I was talking about my customElement. I will edit the question immediately. I did define delimiter of course, however I didn’t think it was that important to show.
