# Read more button problem

**URL:** <https://forum.wixstudio.com/t/read-more-button-problem/17619>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [July 2, 2019, 8:53pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619 "2019-07-02T20:53:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 2, 2019, 8:53pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/1 "2019-07-02T20:53:12Z")

</div>

I cannot seem to be able to get my read more button to show the rest of the text and not be so far away from the box. Can anybody help? Been on the phone to Wix for 1h and they told me to come here.

A

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/8/e80b9957ef911b87070bb0487b4ff0fcfda9e757.jpeg)

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [July 2, 2019, 9:57pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/2 "2019-07-02T21:57:56Z")

</div>

Have you followed the tutorial correctly?  
[https://support.wix.com/en/article/corvid-tutorial-creating-a-show-more-link](https://support.wix.com/en/article/corvid-tutorial-creating-a-show-more-link)

Have a look at this previous forum post as I think it applies to what you are talking about.  
[https://www.wix.com/corvid/forum/community-discussion/expandable-text-box-w-show-more-button-issue](https://www.wix.com/corvid/forum/community-discussion/expandable-text-box-w-show-more-button-issue)

Code for the “Show More” Button

```javascript
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w("#myTextElement").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("#myTextElement").text = shortText;
});

export function mybutton_click(event, $w) {
//making sure that you have added the onClick event in properties
// display the full text
$w("#myTextElement").text = fullText;
// collapse the button
$w("#myButton").collapse();
}

```

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 2, 2019, 10:06pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/3 "2019-07-02T22:06:03Z")

</div>

@azharaonthenet , that’s happening because you put the full text in the text-box (via the editor) and then when you push the short text pragmatically, the element below it stays where it is.  
You should put the short-text (or even no text) in the text-box, and then assign the full text when it’s needed.

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 10, 2019, 7:43pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/4 "2019-07-10T19:43:21Z")

</div>

I JD yeah I did follow correctly, but I am new to this world so could have easily made a mistake.

I dont understand what you mean by assigning the full text when needed.

Will check the other forum 🙂

Thanks

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 10, 2019, 7:50pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/5 "2019-07-10T19:50:22Z")

</div>

This is my code here

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/2/d218116d47307de7955d7059749219550f9d17a5.png)

And this is what it says when i preview it

 ![](https://us1.discourse-cdn.com/wix/original/3X/6/3/63a062bc243a3fece8b0b30dbabc9942d5bf0276.png)

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 10, 2019, 8:12pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/6 "2019-07-10T20:12:15Z")

</div>

@azharaonthenet this error is because lines 6 and line 10 that are not wrapped in

```javascript
$w.onReady( function() {
//lines 6-10 should be here
 }) 

```

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 10, 2019, 8:14pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/7 "2019-07-10T20:14:09Z")

</div>

also instead of line 6 use this code:  
fullText = “here’s my full text my full text my full text” //use your actual full text  
After you make the change, you can leave lines 6-8 above the onReady(), and only keep line 10 inside the onReady()

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 12, 2019, 10:20am UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/8 "2019-07-12T10:20:07Z")

</div>

@jonatandor35 I do not understand what you mean by that JD

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [July 12, 2019, 12:36pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/9 "2019-07-12T12:36:20Z")

</div>

@azharaonthenet

You have mixed up the code for the show more button and the show more/show less toggle.

You have to choose between the button or the toggle, you can’t have both in the same code.

Plus, as J.D. says, you have left out the page’s onReady function itself too.

```javascript
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text 

$w.onReady(function () { // <=== You missed out this line here
// how many characters to include in the shortened version

```

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [July 12, 2019, 12:42pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/10 "2019-07-12T12:42:43Z")

</div>

**Code for the “Show More/Show Less” Toggle Button**

```javascript
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w("#myTextElement").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("#myTextElement").text = shortText;
});

export function mybutton_click(event, $w) {
// make sure that you add the onClick event in properties
// check the contents of the text element 
if ($w("#myTextElement").text === shortText) {
// if currently displaying short text, display the full text
$w("#myTextElement").text = fullText;
$w("#myButton").label = "Show less"; 
} else {
// if currently displaying full text, display the short text
$w("#myTextElement").text = shortText;
$w("#myButton").label = "Show more";
}
}

```

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [July 12, 2019, 12:45pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/11 "2019-07-12T12:45:33Z")

</div>

**Code for the “Show More” Button**

```javascript
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w("#myTextElement").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("#myTextElement").text = shortText;
});

export function mybutton_click(event, $w) {
// make sure that you add the onClick event in properties
// display the full text
$w("#myTextElement").text = fullText;
// collapse the button
$w("#myButton").collapse();
}

```

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 12, 2019, 2:01pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/12 "2019-07-12T14:01:13Z")

</div>

@givemeawhisky I think you’re missing the problem that bothers many users here.  
The problem is the relations between the textbox and the element below:  
The thing is that when a textbox expands it pushes down the next element and moves it from its original location, and that is good. However, when a textbox get shortened, it sometimes fails to pull up the element below and it stays in its original location creating an unwanted gap between the textbox and the next element.  
To resolve that, II suggested to put a minimal text in the textbox (as a placeholder) and assign the actual texts by code only so the next element will never have to be pulled up from its original location (onlt to be psuhed down from the original location, which works fine).  
In you code, you put the full text inside the textbox (on the editor) and that’s what causes the issue. Try and see.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 12, 2019, 2:17pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/13 "2019-07-12T14:17:48Z")

</div>

P.S. that happens probably when another element (somewhere on the page) limits the pull-up. But starting from a very short place-holding text can make it easier to deal with.

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 16, 2019, 3:35pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/14 "2019-07-16T15:35:53Z")

</div>

Write guys thanks a lot, I will give your advice a go! 🙂

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 17, 2019, 4:14pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/15 "2019-07-17T16:14:34Z")

</div>

The button position has been fixed yay! However when i click the button it wont show the rest of the text.  
tried with the both types of code separately.

cheers

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 17, 2019, 4:59pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/16 "2019-07-17T16:59:26Z")

</div>

Paste your full code here (not a screenshot), and I’ll try to have a look.

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 17, 2019, 5:05pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/17 "2019-07-17T17:05:46Z")

</div>

**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 = 471;  
// 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 mybutton\_click(event, $w) {  
// make sure that you add the onClick event in properties  
// display the full text  
$w(“#text3”).text = fullText;  
// collapse the button  
$w(“#button1”).collapse();  
}

Thank you

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 17, 2019, 5:16pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/18 "2019-07-17T17:16:23Z")

</div>

You have a line:

```javascript
 fullText = $w("#text3").text; 

```

instead of this line, put this one:

```javascript
 fullText = "fulltext fulltext fulltext ";//put you real full text between the quote marks instead of my "fulltext fulltext fulltext ",

```

---

<div class="post-metadata">

**Author:** ![azharaonthenet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/azharaonthenet/32/13123_2.png) [@azharaonthenet](https://forum.wixstudio.com/u/azharaonthenet)\
**Post date:** [July 17, 2019, 5:26pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/19 "2019-07-17T17:26:05Z")

</div>

I did so, and it doesn’t work unfortunately

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [July 17, 2019, 5:27pm UTC](https://forum.wixstudio.com/t/read-more-button-problem/17619/20 "2019-07-17T17:27:46Z")

</div>

What did happen when you did it? Do you have the same problem ? something else?

[Next page](https://forum.wixstudio.com/t/read-more-button-problem/17619.md?page=2)
