0

I am having an asp.net sever control as below

<asp:HyperLink Visible='<%# (GetAnswer(Eval("AnsQID"))) != 1 %>' ID="HyperLink1"
  runat="server" NavigateUrl="#" ToolTip='Like this answer' 
  onclick="javascript:(likeThis(this))">Like

</asp:HyperLink>

I am handling this onclick event on the client side by passing to the function on the client side as shown. Here is the "likeThis" function on the client side

function likeThis(e) {
           e.preventDefault(); // how do I get the event arguments as e ?


           var controlBar = ($(e).parents('div[class="group"]').children('p[id="controlBar"]'));
       }

I want the click event to be preventing the default behavior. So can you advise me on how to do that . Thanks

stooicrealism
  • 548
  • 2
  • 9
  • 29
  • [See this old Stackoverflow question.](http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie-any-help) Internet Explorer doesn't understand the "preventDefault()" function like that. It has its own way of doing the same thing however. – Pointy Dec 20 '11 at 14:18

2 Answers2

1

How about something like that: $("a.yourLinks").click(function() { return false; });

Ido Green
  • 2,795
  • 1
  • 17
  • 26
0

You could try using window.event.preventDefault() instead; that should have the same effect. However, you really would be better off assigning your event handlers in Javascript (using jQuery it's very easy, provided you can identify the correct DOM elements) rather than inline, since it gives you much greater control and results in much cleaner (and easier to maintain) code.

Anthony Grist
  • 38,173
  • 8
  • 62
  • 76
  • good suggestion. I already am using jquery almost everywhere I need the sort of thing. But in this case I cannot use it because the part is coming from a repeater group and every a tag in every group does something different. It identifies all elements within that group, so the identity is relative only within that scope and not anywhere else. thanks EDIT : the window.event.preventDefault() does not work either. – stooicrealism Dec 20 '11 at 14:15
  • But only Internet Explorer keeps "event" as a global property of "window". He's using jQuery, and jQuery normalizes the "event" object so that it works consistently across different browsers (as you probably know :-) – Pointy Dec 20 '11 at 14:16