This is based on a few assumption of what I think you want. From the comments and the question I understand that the user should be sent to 'home.jsp' if the outer div doe snot have the logout class or to 'logout.jsp' if it does. If that's correct you can cahnge the html to
<div class="element logout">
<div class="subTop">
<a href="home.jsp" data-confirmmsg="Do you want to logout?" >Log Out</a>
</div>
</div>
and the JavaScript to
jQuery(".subTop>a").click(function(e){
e.preventDefault();
});
jQuery(".element").click(function(e){
var self = jQuery(this),
isLogout = self.hasClass('logout')
anchor = self.find(".subTop>a")
href = isLogout ? "logout.jsp" : anchor.attr('href');
if(!isLogout || (isLogout && confirm(anchor.data('confirmmsg'))))
{
window.location.href=href;
}
});
The first part of the Javascript simply disables the a
-tag as a link. Nothing happens aside from propagating the event to the outer elements (in case the click was actually on the link we'd still wnt to let the `div-tag handle it). The second part of the JavaScript starts by checking whether the logout class is present or not and sets the href accordingly. finally if the user is being sent to 'logout.jsp' the confirm box will be shown and the return value tested.