开发者

How to assign a link to a div and have it open in a new window

开发者 https://www.devze.com 2023-01-06 17:16 出处:网络
I have my click function set up to look for the first link in the div and assign that link to the entire div.

I have my click function set up to look for the first link in the div and assign that link to the entire div.

$('.article-excerpt').click(function() {
 var newLink = $(this).find('a:first-child').attr("href");
 if(newLink != "" && newLink != "#") {
  window.location.href = newLink;
 }
 return false;开发者_StackOverflow社区

});

How can I also make that link in a new window?


$('.article-excerpt').click(function() { 
  var newLink = $('a:first-child',this).attr("href"); 
  if(newLink != "" && newLink != "#") { 
    window.open(newLink);
  }
  return false;
});


window.open(newLink)
0

精彩评论

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