user2405469
user2405469

Reputation: 2003

javascript using the original string instead of the substring

I'm not sure how informative the title is but here is what I am doing...

I have a vertical menu on the left of my page which has smallish paragraphs set out in a list and I am using javascript's substring method to truncate the number of words and replace them with three dots, call it 'ellipsing' or whatever you may.

However is there any way to keep that view but also make it so that when I click on one of the paragraphs it uses the entire/original string that was there? because so far it only retrieves the truncated string.

Further to add the so called paragraphs are actually text that are pulled out from a database and put in the div tag...using asp here.

Upvotes: 0

Views: 96

Answers (2)

Abhitalks
Abhitalks

Reputation: 28387

Create a css class like this:

.ellip {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

Apply this class to your menu items (paragraphs as you call them). The parent of those menu-items should have a width.

See this fiddle: http://jsfiddle.net/88mmf/

This will help you understand how to use javascript or jQuery to toggle this class on click.

Hope that helps.

Upvotes: 1

Samuel
Samuel

Reputation: 2156

You can keep the whole strings in a global array (window.labels), and reference them either in the truncated version or the full text version:

window.labels = [];
window.labels[0] = 'very long string bla bla bla';
window.labels[1] = ...

Upvotes: 0

Related Questions