tags:

views:

56

answers:

3

Right. So here we go.

I am currently using the following code to target all links and apply an 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");
});

it doesn't work. I've tried

.has
.contains

But I suppose I am not familiar with jquery enough at this point.

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

or

$("a[href^='http://www.twitter.com']")
RoToRa
Solid. But it is being used for all outgoing twitter links (multiple twitter accounts... That seems to just target url 'http://www.twitter.com'
stolkramaker
A: 

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

great_llama
So $("a[href^='http:']").filter("[href*='www.twitter.com']").each(function(){ });works but $this.attr('target','_blank'); doesn't..
stolkramaker
Done! It works$("a[href^='http:']").filter("[href*='www.twitter.com']").attr('target','_blank');one line, not a function. Done.
stolkramaker
A: 

I've managed to get this working using

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

Using the .each function seemed to bug out especially when applying the .attr

stolkramaker
Inside the function you put into each(), $this isn't a variable unless you make it one...$this = $(this);
great_llama