Hey there CSS-Tricks community.
I am working on a info-heavy website and need to be able to hide some of the text and do a read more button/link when clicked revels the rest of the text. I have been able get it to work before on single instances but need a way for multiple instances on one page. Can anyone recommended a way to do this with jQuery?
Super simple stuff. Why not wrap the content you want initially hidden in a div, slap an h3 or something in before it, and go something like this:
// Hide the extra content initially, using JS so that if JS is disabled, no problemo.
$('.read-more-content').addClass('hide');
// Set up the toggle.
$('.read-more-toggle').on('click', function() {
$(this).next('.read-more-content').toggleClass('hide');
});
Edited to add: After reading the link you posted, I think I may have misunderstood what you're wanting. If you want this to be inline, the concept is similar, and only slightly more complicated. You could wrap the content you want to be expanded in a span, and use JS to dynamically insert a 'read more' link. I'll fork my CodePen with an example, one sec.
Edit: Didn't see your reply. No problem, glad I could help!
Here's another example, of this done inline, more like the expander plugin but without the added dependency (or features). This is hacked together, and could certainly be done cleaner, just as a disclaimer.
Edited again: Cleaner version with no HTML injection, but this also removes a lot of the convenience of just adding a class to a span to handle everything for you: http://codepen.io/JoshBlackwood/pen/pEwHe
Hey there CSS-Tricks community. I am working on a info-heavy website and need to be able to hide some of the text and do a read more button/link when clicked revels the rest of the text. I have been able get it to work before on single instances but need a way for multiple instances on one page. Can anyone recommended a way to do this with jQuery?
I know about http://plugins.learningjquery.com/expander/ but need away to pick where the break happens not dependent on the number of words or characters.
Thanks in advance!
Super simple stuff. Why not wrap the content you want initially hidden in a div, slap an h3 or something in before it, and go something like this:
CodePen: http://codepen.io/JoshBlackwood/pen/tmpwq
Edited to add: After reading the link you posted, I think I may have misunderstood what you're wanting. If you want this to be inline, the concept is similar, and only slightly more complicated. You could wrap the content you want to be expanded in a span, and use JS to dynamically insert a 'read more' link. I'll fork my CodePen with an example, one sec.
Solid. This should work great. I have know how to implement jQuery just now getting into understanding and writing it. Thanks again.
Edit: Didn't see your reply. No problem, glad I could help!
Here's another example, of this done inline, more like the expander plugin but without the added dependency (or features). This is hacked together, and could certainly be done cleaner, just as a disclaimer.
http://codepen.io/JoshBlackwood/pen/tDsEh
Edited again: Cleaner version with no HTML injection, but this also removes a lot of the convenience of just adding a class to a span to handle everything for you: http://codepen.io/JoshBlackwood/pen/pEwHe
Even better. Yeah both great, love the HTML injection format, much easier. Thanks again!
And how could I achieve that if I click on a closed div´s read more that the other opened div´s will close?