# problem $w() is not a function

**URL:** <https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [June 1, 2020, 5:09pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219 "2020-06-01T17:09:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 1, 2020, 5:09pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/1 "2020-06-01T17:09:45Z")

</div>

hello every body and sorry for my bad english

does somebody knows why this code does not work?: i have the message $w() is not a function

**for** ( **var** i = 0 ; i \< $w( “#dynamicDataset” ).getCurrentItem().equipements.length; i++) {

$w(`"#cat"+i`).show();  
//let x=“#cat”+1  
//$w(“#cat”+x).show()

//let rech=$w(“#dynamicDataset”).getCurrentItem().equipements[i]  
[//wixData.query](https://wixData.query)(“equipements”)  
//.contains(“title”,rech)  
//.then((result2)=\>{

// $w(“#act” + i+1).src=result2.items.icon  
//});  
}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 2, 2020, 2:39am UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/2 "2020-06-02T02:39:10Z")

</div>

Is your page setup like this here.

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/1/31e3a494b3a7c7c3605eeb323d34dbb758019342.png)

With the error being shown in the developer console window in the preview mode?  
TypeError: $w(…).getCurrentItem is not a function

This usually means that you can’t use it like that, so you have to look at a different way of writing your code.

Which in your case, it is the second command of your for loop which is the condition that is not correct. The loop will only run whilst this condition is true.

I think for starters that you can’t use a dataset like that in a for loop.  
[https://www.w3schools.com/js/js\_loop\_for.asp](https://www.w3schools.com/js/js_loop_for.asp)  
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)  
[https://stackoverflow.com/questions/9266739/javascript-for-var-i-0-browser-incompatibilities](https://stackoverflow.com/questions/9266739/javascript-for-var-i-0-browser-incompatibilities)

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 2, 2020, 2:41am UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/3 "2020-06-02T02:41:22Z")

</div>

This has also been talked about in similar posts here.  
[https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections](https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections)  
[https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections-1](https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections-1)

Where they both use the for loop in code as this.

```javascript
 for (var i = 0; i < result.items.length; i++){

```

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 2, 2020, 2:42am UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/4 "2020-06-02T02:42:33Z")

</div>

Also, check the second link from above, as Yisreal has mentioned in that forum post about using it like this below, which might be of benefit to you.

```javascript
let dataset = $w("#dynamicDataset");

```

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 12:52pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/5 "2020-06-02T12:52:38Z")

</div>

Thanks for this answer but the loop is correct and works. This is this code: $w(`" [#cat](https://www.wix.com/corvid/forum/search/~num~cat) "+i`).show(); who’s not work . I think it is because i is not a string. how to convert i to string ?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 1:09pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/6 "2020-06-02T13:09:39Z")

</div>

The variable i is converted to a string when it is concatened to a string.

```javascript
$w('#cat'+i).show()

```

This will work if #cat1 is an element on the screen. If the element is #cat01, then you will have to pad with 0.

Also, I see that the for loop is outside the onReady() function. The $w context selector is not accessible outside of the onReady() or other event handlers (e.g. onClick, onChange, etc).

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 1:34pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/7 "2020-06-02T13:34:31Z")

</div>

@yisrael-wix Hello brewmaster  
My code is in onReady()  
And this code give me the same error message

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 1:39pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/8 "2020-06-02T13:39:55Z")

</div>

Please post the editor URL of your site. _Only authorized Wix personnel can get access to your site in the editor._ **Please include the name of the page involved.**

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 1:48pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/9 "2020-06-02T13:48:11Z")

</div>

ok, it is page “Entreprises Francophones Detail”  
problem line 40

[https://editor.wix.com/html/editor/web/renderer/edit/fa9ca072-2b07-4274-8cf8-810116b786cc?metaSiteId=54ba3451-ea8f-467c-a640-67e0b290e628&editorSessionId=c6abea8d-a58b-426c-bf51-6cbc9f096252&referralInfo=dashboard](https://editor.wix.com/html/editor/web/renderer/edit/fa9ca072-2b07-4274-8cf8-810116b786cc?metaSiteId=54ba3451-ea8f-467c-a640-67e0b290e628&editorSessionId=c6abea8d-a58b-426c-bf51-6cbc9f096252&referralInfo=dashboard)

thanks a lot

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 1:58pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/10 "2020-06-02T13:58:17Z")

</div>

The line you have is incorrect.

```javascript
$w(`#cat+i`).show();

```

The backticks, turn everything inside of them into a string. Therefore, what you end up with is an element Id of ‘#cat+1’.

What you want is:

```javascript
$w('#cat'+i).show();

```

What this does is takes the string ‘#cat’ and then appends (as a string) the number contained in i.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 2:02pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/11 "2020-06-02T14:02:52Z")

</div>

You can also do this:

```javascript
$w(`#cat${i}`).show();

```

For more information on template literals (strings inside of back ticks), see this article.

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 2:10pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/12 "2020-06-02T14:10:34Z")

</div>

@yisrael-wix Sorry but i just test the 2 codes and i have exactly the same error message…i don t

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 2:20pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/13 "2020-06-02T14:20:34Z")

</div>

@fredericmassard Where are the #cat screen elements? I can’t find them.

Plus, when I load the page, I don’t get the error. I don’t think that code runs at all when I load the page. How do you load the page?

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 2:24pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/14 "2020-06-02T14:24:48Z")

</div>

Are you trying to reference #cat1 or #act1?

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 2:35pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/15 "2020-06-02T14:35:13Z")

</div>

Elements are act1 act2 act3…

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 2:35pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/16 "2020-06-02T14:35:49Z")

</div>

elements are here

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/6/960360bd4f4144e641b996b6959f3fd14465d593.png)

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 2:36pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/17 "2020-06-02T14:36:23Z")

</div>

I load directly from wix

 ![](https://us1.discourse-cdn.com/wix/original/3X/c/d/cd441b0e6a93a36c088f2a30d0b9c927143a6828.jpeg)

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 2:36pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/18 "2020-06-02T14:36:26Z")

</div>

So you want this:

```javascript
$w(`#act${i}`).show();

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [June 2, 2020, 2:37pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/19 "2020-06-02T14:37:56Z")

</div>

Please realize that your page is quite complex, having many components. We are unable to debug or rewrite extremely complex code/pages. Please try to isolate the problem to a minimal scenario so that we can properly evaluate your problem.

---

<div class="post-metadata">

**Author:** ![fredericmassard](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@fredericmassard](https://forum.wixstudio.com/u/fredericmassard)\
**Post date:** [June 2, 2020, 2:42pm UTC](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219/20 "2020-06-02T14:42:46Z")

</div>

Ok

[Next page](https://forum.wixstudio.com/t/problem-w-is-not-a-function/20219.md?page=2)
