开发者

jQuery auto click issue

开发者 https://www.devze.com 2023-04-05 01:00 出处:网络
I have written code which responds to an image begin clicked by auto clicking a link in the navigation b开发者_开发知识库ar by the following code:

I have written code which responds to an image begin clicked by auto clicking a link in the navigation b开发者_开发知识库ar by the following code:

$('body.node-4 div#block-views-Poster-block_1 img.imagecache-Posters').addClass('manually-linking').click(
function(){
    //$('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'red').trigger('click');
    $('body.node-4 div#block-menu-primary-links ul li a.menu-224').css('color', 'green').click();
}
);

In each case, .trigger('click') and .click(), I am applying color via CSS to the target link. When the image is clicked, the target link changes color but the navigation to the relevant page never happens.

What might I be doing wrong?


Wouldn't it be easier to simply redirect to that URL, instead of actually triggering the click?

    $(".imagecache-Posters").click(function(){
      var url = $(".menu-224").attr("href");
      location.href = url;
   });

I assume you are changing the colour of the link, merely to confirm that it targets properly (as it will of course be reset, when the page reloads).

0

精彩评论

暂无评论...
验证码 换一张
取 消