-5

This is my existing work. I made it to limit the characters up to 30 but how would I add a read more link to my other page dynamically when characters exceed the limit? i need your help guys.

var myDiv = $('.wwdtext'); myDiv.text(myDiv.text().substring(0,30)) <div style="background-color:#FF6201;width:220px;height:220px"> <div class="wwdtext">Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World</div> </div> 
8
  • 2
    Tell us about your attempts? Commented Mar 8, 2018 at 8:33
  • and you found nothing about this on Google ?? Commented Mar 8, 2018 at 8:34
  • Why tag jQuery if you use pure JS? Commented Mar 8, 2018 at 8:39
  • I don't know if it works more easier in jquery? Commented Mar 8, 2018 at 8:41
  • truncated = truncated.substr(0,maxLength) + '<span class="more">...</span><span style="display:none">'+truncated.substr(maxLength)+'</span>'; - now wire up class more to show next sibling Commented Mar 8, 2018 at 8:43

1 Answer 1

0

var myDiv = $('.wwdtext'); myDiv.text(myDiv.text().substring(0,100))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div style="background-color:#FF6201;width:220px;height:220px"> <div class="wwdtext">Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldeqwrewqjkfbsajHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldeqwrewqjkfbsajHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello Worldeqwrewqjkfbsaj</div> </div>

Sign up to request clarification or add additional context in comments.

6 Comments

How do i get a button with that?
I need to have a read more link or button when it exceeds the character limit.
@user3117337 add <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> before </body> tag , also add <script>var myDiv = $('.wwdtext'); myDiv.text(myDiv.text().substring(0,100));</script>
I tried this on jsfiddle but still doesnt generate the button.
I need to dynamically add a button when it exceeds the limit.. plss heeelp
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.