Yahua++;

Thank you!
-js


On 12/29/06, Yehuda Katz <[EMAIL PROTECTED]> wrote:

The issue is that you can't trigger a link's default action via a click.
I've worked around it with the following code:

    jQuery("table.data_panel tr").each(function(){
      if(jQuery("a", this).length == 1) jQuery(this).click(function(e) {
        var link = jQuery(this).find("a")[0];
        if(!jQuery(e.target).is(":input") && !jQuery(e.target).is("option")
&& !link.onclick) {
          window.open(link.href , link.target || "_self");
          return false;
        } else if(!jQuery(e.target).is(":input") && 
!jQuery(e.target).is("option")
&& link.onclick) {
          jQuery(link).click();
          return false;
        }
      });
    });

That code is a bit more complex, because it tests for other situations,
but the meat of it, which is:

var link = jQuery("> a", this)
if(!link.onclick) window.open(link.href, link.target || "_self")
else jQuery(link).click()

is what you need. That will open the link with the current target
(defaults to self) if there's no existing click binding, otherwise it'll
fire the click event.

-- Yehuda

On 12/29/06, Jonathan Sharp <[EMAIL PROTECTED]> wrote:

> I'm embarassed to post this, but is the click() method not supported for
> links to trigger them?
>
> I have a div that has a link inside of it that I want to trigger as if
> someone clicked that link when they click the div.
>
> <div id="foo">
> <a href="http://jquery.com";>MyLink</a>
> </div>
>
> $('#foo').bind('click', function(){
>      // Works in IE, not Firefox
>      $('> a', this)[0].click();
>      // I've also tried
>      $('> a', this).trigger('click');
> });
>
> Does the click method just not work like I am expecting it to?
>
> -js
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
>


--
Yehuda Katz
Web Developer | Wycats Designs
(ph)  718.877.1325
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to