Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why not firing click function of 'linkLogutUser' id

XML
<div id="logoutDiv" >
  <p class="logoutDivPTag">India(Rs.)</p>
  <b class="caret" style="color:White; display: inline-block;width: 0;height: 0;margin-left: 2px;vertical-align: middle;border-top: 4px dashed;border-top: 4px solid\9;border-right: 4px solid transparent;border-left: 4px solid transparent;"></b>&nbsp
  <img id="logoutLogo" src="images/logoutLogo.png" alt="" width="28"height="12"/>
  <a id="linkLogutUser" href="">LOGOUT</a>&nbsp
  <img id="myAccLogo" src="images/myAccLogo.png" alt="" width="28"height="12"/>&nbsp
  <p class="logoutDivPTag">MY ACCOUNT</p>&nbsp
  <img id="CartLogo" src="images/CartLogo.png" alt="" width="28"height="12"/>
  <p class="logoutDivPTag">CART</p>
</div>




<script type="text/javascript">
    $(function () {
        $(document).on('click', '#linkLogutUser', function () {
            alert('link logout');
            var cookies = document.cookie.split(";");
            
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                var eqPos = cookie.indexOf("=");
                var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
                document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
            }
            window.location.href = "Index.aspx";
        });
Posted
Updated 4-Oct-15 23:12pm
v2
Comments
F-ES Sitecore 5-Oct-15 5:13am    
Try giving it a non-empty href

a id="linkLogutUser" href="#">LOGOUT
Dawood507 5-Oct-15 5:27am    
tried..not working
Krunal Rohit 5-Oct-15 5:30am    
Have you check the browser console after clicking the link ?

-KR
Dawood507 5-Oct-15 5:46am    
I got it its css side problem.
Krunal Rohit 5-Oct-15 5:49am    
And what is that ?

―KR

Hi Dawood Please Please add a new page and replace the source code with below. Run that page and click on logout your alert dialogue will appear. Its tested and running ..

C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#linkLogutUser').click(function () {
                alert('link logout');
                var cookies = document.cookie.split(";");

                for (var i = 0; i < cookies.length; i++) {
                    var cookie = cookies[i];
                    var eqPos = cookie.indexOf("=");
                    var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
                    document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
                }
                window.location.href = "Index.aspx";
            });
        });
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <a id="linkLogutUser" href="#">LOGOUT</a>    
    </div>
    </form>
</body>
</html>
 
Share this answer
 
v4
Comments
Dawood507 5-Oct-15 5:26am    
I tried this alredy...not working..
Dawood507 5-Oct-15 9:09am    
Yeah It was working..it was css side design problem..I make all p tags in inline..so its working properly.
I think you will need to prevent the default action of the anchor tag here like:

JavaScript
$(document).on('click', '#linkLogutUser', function (event) {
    event.preventDefault();
    alert('link logout');
    // your code here...
});


and also put '#' in the href like:

HTML
<a id="linkLogutUser" href="#">LOGOUT</a>
 
Share this answer
 
Comments
Krunal Rohit 5-Oct-15 5:46am    
No. this will not perform any action written after preventDefault();

-KR
Palash Mondal_ 5-Oct-15 5:51am    
Please check this fiddle Fiddle[^]. alert is still coming after preventDefault.
Krunal Rohit 5-Oct-15 6:12am    
Maybe jQuery version issue ;)

-KR
Palash Mondal_ 5-Oct-15 6:15am    
Yeah, I think so. Anyways, it was a CSS issue. It would be interesting to know from OP what css prevented the click event in first place. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900