I have problem when I’m creating multiple “Show more” links on one page, as per insturction on: https://support.wix.com/en/article/wix-code-tutorial-creating-a-show-more-link
It works fine when I only create one “Show more button” and text box. However, the problem is that when I create second “Show more button” and text box. Both buttons only display second text box when click.
My example:
The first “show more button” and text box id are #button3 and #text35
The second “show more button” and text box id are #button4 and #text36
I want full text of #text35 displayed when click #button3 and full text of #text36 displayed when click #button4.
However, once I created the below code, by clicking either button3 or button4, only #text36 displayed under both buttons.
Anyone know how to resolve it?
Code:
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
$w.onReady( function () {
//how many characters to include in the shortened version
const shortTextLength = 0;
//read the full text and store it in the fullText variable
fullText = $w(“#text35”).text;
//grab the number of characters defined in shortTextLength and store them in the shortText variable
shortText = fullText.substr(0, shortTextLength);
// set the contents of text35 to be the short text
$w(“#text35”).text = shortText;
});
export function button3_click(event, $w) {
// check the contents of the text element
if ($w(“#text35”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text35”).text = fullText;
$w(“#button3”).label = “- Plan your departure”
} else {
// if currently displaying full text, display the short text
$w(“#text35”).text = shortText;
$w(“#button3”).label = “+ Plan your departure”
}
}
$w.onReady( function () {
//how many characters to include in the shortened version
const shortTextLength = 0;
//read the full text and store it in the fullText variable
fullText = $w(“#text36”).text;
//grab the number of characters defined in shortTextLength and store them in the shortText variable
shortText = fullText.substr(0, shortTextLength);
// set the contents of text36 to be the short text
$w(“#text36”).text = shortText;
});
export function button4_click(event, $w) {
// check the contents of the text element
if ($w(“#text36”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text36”).text = fullText;
$w(“#button4”).label = “- Arrival”
} else {
// if currently displaying full text, display the short text
$w(“#text36”).text = shortText;
$w(“#button4”).label = “+ Arrival”
}
}