Yusaf Khaliq
Yusaf Khaliq

Reputation: 3393

Add attribute to wrap element with jQuery

<a href="random-link">
<img alt="My Photo" class="profile-img" height="80" src="img" width="80">
</a>

how do you apply this jquery .attr('target','_blank'); to the <a href="link"> so the outcome will be

<a href="random-link" target="_blank">
<img alt="My Photo" class="profile-img" height="80" src="img" width="80">
</a>

Upvotes: 1

Views: 598

Answers (1)

zzzzBov
zzzzBov

Reputation: 179176

Just in case @Yusaf was using link as an ambiguous link, you could try this instead:

$('.profile-img').parent('a').attr('target', '_blank');

Upvotes: 3

Related Questions