Skip to content

Instantly share code, notes, and snippets.

@ronan-mch
Created September 27, 2012 15:26
Show Gist options
  • Save ronan-mch/3794615 to your computer and use it in GitHub Desktop.
Save ronan-mch/3794615 to your computer and use it in GitHub Desktop.
clever jQuery function to show more or less of an item
//call relevant function on click of showMore/Less links
$("[id^=show]").click(function(){
var functionCall = $(this).attr("id").substring(4,8);
var boxName = $(this).attr("id").substring(8);
window["show" + functionCall](boxName);
});
/**
* @param boxName string
* @pre boxName = Subjects || Notes
* @post moreBoxName = hidden
*
* hides box with id from param
*/
function showLess(boxName){
var divId = "#more" + boxName;
var moreLink = "#showMore" + boxName;
$(moreLink).show();
$(divId).hide();
};
/**
* @param boxName string
* @pre boxName = Subjects || Notes
* @post moreBoxName = shown
*
* displays box with id from param
*/
function showMore(boxName){
var divId = "#more" +boxName;
var moreLink = "#showMore" + boxName;
$(moreLink).hide();
$(divId).show();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment