0

Possible Duplicate:
re-firing a click event on a link with jQuery

Is is possible to tigger an anchor link being clicked when checking a checkbox?? Below is my html and jQuery

Html:

<div id="filter-1" class="filter tags">
 <ul>
  <li class="grey">
    <input type="checkbox">
    <a title="" href="/collections/mens/grey">Grey</a>
  </li>

 <li class="all">
   <input type="checkbox">
   <a title="" href="/collections/mens">All color</a>
  </li>
 </ul>
 </div>

jQuery:

 $("input[type='checkbox']").change(function(){
  var item=$(this);    
   if(item.is(":checked"))
    {
     item.siblings('a').trigger('click');
    }    
 });
Community
  • 1
  • 1
user992731
  • 3,400
  • 9
  • 53
  • 83

1 Answers1

5
 $("input[type='checkbox']").change(function(){
  var item=$(this);    
   if(item.is(":checked"))
    {
      location.href = item.siblings('a').attr('href');
    }    
 });
codingbiz
  • 26,179
  • 8
  • 59
  • 96
  • whatever you wanna achieve with that, I think this should help... :) – codingbiz Dec 25 '12 at 23:24
  • if he's trying to actually trigger the `click` event in order to run code bound to that event, then this will not work however. – Zach Lysobey Dec 25 '12 at 23:26
  • This actually got me curious, and I did some [jsfiddlin'](http://jsfiddle.net/yY4Nc/) and searchin'.. It looks like, technically, OP's code probably *was* "triggering" the click event, but this is not equivalent to actually "clicking" the link. See [this answer to another SO post](http://stackoverflow.com/a/12166799/363701). – Zach Lysobey Dec 25 '12 at 23:39