Reputation: 105
In SharePoint, I am trying to be able to click anywhere in the group by header element and have the group expand/collapse. I have gotten it to work partially. Right now I can click anywhere in the element except on the <a>
tag that opens it. How do I set the conditional to run the function when anywhere is clicked except the <a>
tag?
Here is what I have:
$(document).ready(function() {
var groupby = $(".ms-gb");
groupby.click(function(){
var groupbyAnchor = $("a", this);
groupbyAnchor = groupbyAnchor[0];
expandThisGroup(groupbyAnchor)});
});
function expandThisGroup(anchor) {
anchor.click();
}
Upvotes: 0
Views: 61
Reputation: 911
You might do it like this. Pass the click
event target to the function, if the target is not the given anchor
, do something, else do nothing.
$(document).ready(function(){
var groupby = $(".ms-gb");
groupby.on('click', function(e){
var $target = e.target,
$anchor = $('a', this);
if(!($target == $anchor)){
// do function
}else{
return false;
}
});
});
Upvotes: 1
Reputation: 781059
Put another handler on the child element that prevents event propagation:
groupby.find("a").click(function(e) {
e.stopPropagation();
});
Upvotes: 1