Skip to content

Instantly share code, notes, and snippets.

@aldelpech
Last active August 29, 2015 14:27
Show Gist options
  • Save aldelpech/732f63f2e7943477c8ee to your computer and use it in GitHub Desktop.
Save aldelpech/732f63f2e7943477c8ee to your computer and use it in GitHub Desktop.
How to add a specific class to a link (<a>) with an image nested into it ?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a:has(img)").css("border", "solid red");
});
</script>
</head>
<body>
<p><span>This is a span element inside a p element.</span></p>
<p>This is a p element with no span element.</p>
<a href="https://www.flickr.com/" target="_blank"><img class="alignnone wp-image-3813 size-full" src="http://testal.parcours-performance.com/wp-content/uploads/2015/08/837bb5351b255cdb3e1defb65ede240f-1200-x-450.jpg" alt="image 1200 px par 450px" width="1200" height="450"></a>
</body>
</html>

jPoMxY

How to add a specific class to a link () with an image nested into it ?

I wanted to add an icon to links in external window (target = blank) but this icon also showed near images with an external link. So I found a way to change the display of the icon when the was followed by an And it works !

A Pen by Captain Anonymous on CodePen.

License.

img {
max-width: 600px;
height: auto;
}
a[target="_blank"]::after {
content: "external";
display: inline-block;
font-family: FontAwesome;
font-size: 150%;
color: #fa5c5d;
text-decoration: underline;
text-align: right;
margin-left: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment