TheWebs
TheWebs

Reputation: 12913

Opening links in a new tab, Jquery

Is there a way to take:

$(function(){
  $("#myDiv a").attr("target","_blank");
});

and say all links in #mydiv that don't have a class of btn should open in a new tab?

Upvotes: 1

Views: 16

Answers (1)

Barmar
Barmar

Reputation: 782166

Use a :not modifier in the selector.

$("#myDiv a:not(.btn)").attr("target", "_blank");

Upvotes: 1

Related Questions