2

Think this is a quickie for someone. I have this markup (generated by ASP.Net)...

<A id=anchorO href="javascript:__doPostBack('anchorO','')">O</A>

This anchor is in an update panel, and if I click it manually a partial postback takes place. However....

$('[ID$="anchor'+initial+'"]').click()   //JavaScript

..selects the correct anchor, but no postback takes place. Why is this?

El Ronnoco
  • 11,753
  • 5
  • 38
  • 65

2 Answers2

6

A click and a href are seen as two different things in Javascript, so you can't do .click() and call the href, regardless if this is calling javascript: or not

Two options:

  1. Just do:

    $('#anchor' + initial).click(function() { __doPostBack('anchorO',''); });
    
  2. Be evil and use eval:

    $('#anchor' + initial).click(function() { eval($(this).attr('href')); });
    
Gary Green
  • 22,045
  • 6
  • 49
  • 75
  • +1 Thanks, I actually used the method 1 (evil eval indeed!) however I didn't actually bind it to the click event using `click()` I just force the postback instead of doing any clicking. Thanks! – El Ronnoco Apr 15 '11 at 10:41
1

See this question here

It appears that you can't follow the href of an a tag using the click event.

Community
  • 1
  • 1
lxalln
  • 930
  • 11
  • 29