Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created April 7, 2017 15:12
Show Gist options
  • Save gagimilicevic/b674d35139af559f0dd26f7e67ae7adf to your computer and use it in GitHub Desktop.
Save gagimilicevic/b674d35139af559f0dd26f7e67ae7adf to your computer and use it in GitHub Desktop.
Read More - Read Less javascript snippet
jQuery(document).ready(function($){
var minimized_elements = $('div.minimize');
minimized_elements.each(function(){
var t = $(this).text();
if(t.length < 600) return;
$(this).html(
t.slice(0,600)+'<span>... </span><a href="#" class="more">' + customscript_vars.read_more + '</a>'+
'<span style="display:none;">'+ t.slice(600,t.length)+' <a href="#" class="less">' + customscript_vars.read_less + '</a></span>'
);
});
$('a.more', minimized_elements).click(function(event){
event.preventDefault();
$(this).hide().prev().hide();
$(this).next().show();
});
$('a.less', minimized_elements).click(function(event){
event.preventDefault();
$(this).parent().hide().prev().show().prev().show();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment