Counter for elements

Is there a counter where you can immediately see how many elements have been inserted on a page site?
Thank you.

Yes, you can generate a code, which can do this for you.

What can be done?

  • counting all elements on a page
  • filter elements by theit type
  • getting the values of found elements
  • and so on.

What you will need ?

$w.onReady(()=>{
  console.log($w('#page1');
});

logging your page-element into the CONSOLE, it will give you all data, which will be interessting for your future coding-project.

I went to “Code” and added the text you wrote into the “Page code”.
Where is the “console” located?

I don’t know how to use source code properly, forgive me if I’m asking a stupid question.

Questions are not stupid! There can’t be stupid questions, if you you are iterested to learn something.

So, as you can see → you have some errors shown (red marked) in your code.

I can see, that you are using → $w.onReady(()… more then once, but one $w.onRedy() is absolutely enough for a whole page.

What does do → $w.onReady() ???
This is the starting point of your page’s code.
Once $w.onReady was fired → your wix-page gets/is ready for further actions.
Starting your code (running code) before page is ready and has loaded all needed data → can/will cause problems and issues.

Second what i can see…
-you are not using the right SYNTAX.

What is SYNTAX? → SYNTAY is the coding-alphabet which you can use and also the structure of it.

For example: Everytime you open a —> { you also have to close it at the end → }.
The same for —> [ … ]
The same for —> ( … )

Sometimes you have combinations…

({ <---- what to do here ? Of course —> })
({[ <— what to do here? Of course —> ]})

As you can see → you close in the same order like you have opened a scope.

Another point for writing the right JS-SYNTAX is to add at the end of a coding line a → ;

But the → ; is not urgent needed.

So first DEBUG your existing code…

  1. Remove one $w.onReady-code-part.
  2. Check correct for JS-SYNTAX.

Once you don’t have any red marked CODE-BUGS inside your code, you can do the next step and open the —> CONSOLE <— .

How to do that? → When using CHROME-BROWSER → press-F12 and navigate to → CONSOLE.

Once your console is opened, you will see your own console-log, in this case…

console.log($w(‘#page1’); ← and yes, here i have made an MISTAKE and forgot to close one of the ----> (( <------

CORRECTED-VERSION —> console.log($w(‘#page1’));

And if working with the console → i would recommend to use the BROWSER’s console, this for you will have to publish your website, navigate to the page you are looking for on the LIVE-SITE and open the console with F12 on your keyboard.

Now, check your console → what does it tell you ?
ONLY WHO KNOWS HOW TO USE THE CONSOLE → WILL GET A GOOD CODER!!!

1 Like

Ok, I fixed the code.

So the only way to see the number of content manager elements is after publishing the site?

I am in this situation:
I made a site in 2021 with Wix Editor, now I wanted to move it to Wix Studio but I discovered that it’s not possible.
So I’m rebuilding it on Wix Studio, I wanted to understand how many elements I’m using to evaluate which subscription I’ll have to purchase once I move the domain to this new site.

However, if I can only see how many items I have after publishing it, it means that I cannot understand which subscription is best for me among these:

Just gonna jump in and clarify, these refer to CMS items, not elements in the editor.

CMS items being collections and rows of data, rather than components added to the editor stage :slight_smile:

Hope that helps

Ok, now it’s clear!

I’ll rephrase the question: is there a counter of elements used in the editor?

No, you do again the same mistake :slight_smile:

not elements in the editor.

What you need to know is how much data (data-rows / items) stored inside your DATABASE, or in your words → collection <----(still a bad word for a DATABASE).

However, there are several options of how to count the number of ITEMS inside your DATABSE.

  1. Using a Query (wix-data-api) → query - Velo API Reference - Wix.com + getting the length of the queried data)
  2. using by dataset. —> getTotalCount - Velo API Reference - Wix.com
1 Like

So these codes must always be checked in the console after publishing the site?

Hi Igor

If you simply want to know how many “Elements” (Rows of data) you have in all your collections it’s pretty easy and you don’t need any coding for that.

You can simply press on this button:

Bildschirmfoto 2023-11-22 um 21.05.18

Then you should see all your Collections. Press on one of them and it should open.

Then click on the checkbox in the top left:

Bildschirmfoto 2023-11-22 um 21.06.22

And you should see the total amount of items in that collection (in my case 53). Then repeat this until you have the total number of elements. Just add them up an voilà.

According on that information you then know which Premium package to Choose for your Website.

Hope that helps :slight_smile: