Hi!
I’am trying to figure out how to add multiple show-more links. I’am not super into code so don’t blame me, I tried hahah. This is the code I got so far but issn’t working.
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 1000;
// read the full text and store it in the fullText variable
fullText = $w(“#text6”).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 the text element to be the short text
$w(“#text6”).text = shortText;
});
export function button2_click(event) {
// check the contents of the text element
if ($w(“#text6”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text6”).text = fullText;
$w(“#button2”).label = “Minder”;
} else {
// if currently displaying full text, display the short text
$w(“#text6”).text = shortText;
$w(“#button2”).label = “Lees meer…”;
}
}
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 1000;
// read the full text and store it in the fullText variable
fullText = $w(“#text1”).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 the text element to be the short text
$w(“#text1”).text = shortText;
});
export function button1_click(event) {
// check the contents of the text element
if ($w(“#text1”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text1”).text = fullText;
$w(“#button1”).label = “Minder”;
} else {
// if currently displaying full text, display the short text
$w(“#text1”).text = shortText;
$w(“#button1”).label = “Lees meer…”;
}
}
I found this link: https://support.wix.com/en/article/wix-code-tutorial-creating-a-show-more-link
which works perfectly with one text and one button but when I copy the code to make another show-more link (for #text6 and #button2) the text box (#text6) shows the content of text1 after clicking the “Lees meer…” button (#button2).