Dan
Dan

Reputation: 3358

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

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;

});

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

Upvotes: 0

Views: 336

Answers (2)

Michael Lorton
Michael Lorton

Reputation: 44376

window.open(newLink)

Upvotes: 1

volkan er
volkan er

Reputation: 1012

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

Upvotes: 3

Related Questions