Total coding newbie. I'm wanting to add expand/collapse buttons to two different web part lists on one sharepoint page. The lists are in group view, so I want the buttons to expand or collapse the entire list that they are attached to. I was able to give each list its own set of buttons, but the buttons activate both lists on the page and not just the list they're attached to.
I've seen answers related to this (https://sharepoint.stackexchange.com/questions/25107/expand-collapse-all-grouped-items-in-views-of-a-page), but doesn't function in the way that I need. Any help would be greatly appreciated.
<script type="text/javascript">
function expandAll() {
$('img[alt="expand"]').click();
}
function collapseAll() {
$('img[alt="collapse"]').click();
}
var expandButton = "<a href='#' onClick="
+'"' + "this.href='javascript:expandAll()'"
+ '"> <img title="expand all groups" style="border:none;" alt="expand all" src="/_layouts/images/collapseplus.gif">Expand List</a>';
var collapseButton = "<a href='#' onClick="
+'"' + "this.href='javascript:collapseAll()'"
+ '"> <img title="collapse all groups" style="border:none;" alt="collapse all" src="/_layouts/images/collapseminus.gif">Collapse List</a>';
$(document).ready(function () {
$("#WebPartWPQ2").prepend(expandButton).prepend(collapseButton);
$("#WebPartWPQ3").prepend(expandButton).prepend(collapseButton);
});
</script>