Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
How can I duplicate this .JS function to multiple Elements on the same Wix Page?

What I am basically asking here is: "How do I create two Buttons that do the same thing on the same Wix Page?"

I have added some custom code to create an Expanding Text function for when someone clicks "Read More".

My problem is that I have defined each individual button (total of 4 buttons) and its function like so:

    $w.onReady(function () {
    // Write your JavaScript here
    // column1
    $w("#readMoreButton1").onClick(() => {
        $w("#readMoreStatebox1").changeState("expandedState1");
    });

    $w("#readLessButton1").onClick(() => {
        $w("#readMoreStatebox1").changeState("collapsedState1");
    });
    //column2
    $w("#readMoreButton2").onClick(() => {
        $w("#readMoreStatebox2").changeState("expandedState2");
    });

    $w("#readLessButton2").onClick(() => {
        $w("#readMoreStatebox2").changeState("collapsedState2");
    });
    //column3
    $w("#readMoreButton3").onClick(() => {
        $w("#readMoreStatebox3").changeState("expandedState3");
    });

    $w("#readLessButton3").onClick(() => {
        $w("#readMoreStatebox3").changeState("collapsedState3");
    });
    //column4
    $w("#readMoreButton4").onClick(() => {
        $w("#readMoreStatebox4").changeState("expandedState4");
    });

    $w("#readLessButton4").onClick(() => {
        $w("#readMoreStatebox4").changeState("collapsedState4");
    });

    // To select an element by ID use: $w('#elementID')

    // Click 'Preview' to run your code
});

Read More/Read less Feature

The end result is that the first button/column one works but the rest dont. I have tried changing syntax but I fear that I may be missing something very simple. Can I get some help on this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!