Interesting… Forgive me for my ignorance. The first string of code was under the “site” portion of the code, and the problem that I posted was under the “page” portion. It worked like it should when I moved it all to the same place.
Next question. Should it all be under the “site” or under the “Page”? I’m building a one page site with anchors.
Also, I can only get the first one in the code to work.
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w(“#text9”).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(“#text9”).text = shortText;
});
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// read the full text and store it in the fullText variable
fullText = $w(“#text7”).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(“#text7”).text = shortText;
});
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// read the full text and store it in the fullText variable
fullText = $w(“#text5”).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(“#text5”).text = shortText;
});
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// read the full text and store it in the fullText variable
fullText = $w(“#text3”).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(“#text3”).text = shortText;
});
export function button5_click(event) {
// check the contents of the text element
if ($w(“#text9”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text9”).text = fullText;
$w(“#button5”).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(“#text9”).text = shortText;
$w(“#button5”).label = “Show more”;
}
}
export function button6_click(event) {
// check the contents of the text element
if ($w(“#text7”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text7”).text = fullText;
$w(“#button6”).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(“#text7”).text = shortText;
$w(“#button6”).label = “Show more”;
}
}
export function button7_click(event) {
// check the contents of the text element
if ($w(“#text5”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text5”).text = fullText;
$w(“#button7”).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(“#text5”).text = shortText;
$w(“#button7”).label = “Show more”;
}
}
export function button8_click(event) {
// check the contents of the text element
if ($w(“#text3”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text3”).text = fullText;
$w(“#button8”).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(“#text3”).text = shortText;
$w(“#button8”).label = “Show more”;
}
}
button5 and button8 work fine but the ones between them do not. However, button5 on the first click changes the text to the shortText version of button8 then the second click shows the rest of the text in button8. I have to be missing some sort of code that will allow the first clickevent to be read before going to the next.