tags:

views:

42

answers:

1

can we programatically click on an a href tag using jquery? i have tried $('a#someid').click(); but this does not trigger anything.. although i am using $("a#someid").attr("href", "someurl") to set the href dynamically which works fine..

Also i tried giving window.location = "someurl", but when this is done.. the IE browsers security comes into play and asks for me to download file. which i need to avoid. if the same "someurl" is given as an href to an A tag the url is loaded without any IE securities..

Any help is very much appreciated..

+2  A: 

Taken from : here

Using .trigger('click') will not trigger the native click event. To simulate a default click, you can bind a click handler like so:

$('#someLink').bind('click', function() {
  window.location.href = this.href;
  return false;
});

... where "someLink" is an actual selector of your choice.

You can then trigger that bound click handler if you want, based on some other interaction.

$('input.mycheckbox').click(function() {
  if (this.checked) {
    $('#someLink').trigger('click');
  }
});
Antonio Louro
thnx antonio for your reply.. but the thing is, if i give any url to window.location.href that url will be blocked by the IE security. BUT if the same url isgiven to an href of an A tag and when clicked on it manually. that url will be opened without any IE security blocking..
vinay
That some thigh security you have there:) Sorry for not being of help.
Antonio Louro