How can i access javascript variable in kirby cms for "limit" functionality

hello everyone ,
just like in our demo of kirby
<?php foreach(page('projects')->children()->visible()->limit(3) as $project): ?>
i want to make dynamic limit of records.?
how can i do that?

i have tried javascript but it not worked.

here is javascritps code that no worked

            var p1 = 3;
            function load()
              // echo $number; 
           <?php foreach(page('projects')->children()->visible()->limit($number) as $project): ?>

            <?php endforeach ?>

                    <div class="text-center"><a href="#" class="load-more" onClick="load();">LOAD MORE</a></div>

suggest me if anyone has done it

maybe explain a little bit more what exactly you want to achieve? or provide link to said demo.

you could use pagination to generate a limited list of pages from a collection. if you want something fancier like a β€˜load more’-button you would have read this post.

yes i need load more functionality. do you have any demo for that?