What is the opposite of JQuery.not - OR - How to set up targeted href links that contain the following

Right. So let's go.

I am currently using the following code to cover all links and apply the iframe toolbar

$("a[href^='http:']").not("[href*='www.domiain.com']").not("[href*='www.twitter.com']").each(function(){ 
 var tempurl = 'http://www.domain.com/shiftbar/shiftbar.html?iframe=';
 var $this = $(this);
 var currenturl = this.getAttribute("href");
    var href = tempurl + currenturl;
 $this.attr('href', href ); 
});

      

I need to do the same, but now for links that ONLY contain twitter

$("a[href^='http:']").contains("[href*='www.twitter.com']").each(function(){ 
 $this.attr("target", "_blank");
});

      

he does not work. I tried

.has
.contains

      

But I guess I'm not familiar with jquery at the moment.

+2


a source to share


3 answers


$("a[href^='http:'][href*='www.twitter.com']")

      

or



$("a[href^='http://www.twitter.com']")

      

+3


a source


Use .filter just like in your non-working example.



+3


a source


I managed to get this working using

$("a[href^='http:']").filter("[href*='www.twitter.com']").attr('target','_blank');

      

Using the .each function seemed to be a bug, especially when applying .attr

+1


a source







All Articles