Created
September 27, 2012 15:26
-
-
Save ronan-mch/3794615 to your computer and use it in GitHub Desktop.
clever jQuery function to show more or less of an item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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