Вы можете добавить after
класс с классом.
$('a:not(:has(img))').addClass('after-affect');
a:hover {
position: relative;
}
a.after-affect:hover:after {
content: '';
position: absolute;
left: 0;
display: inline-block;
height: 1em;
width: 100%;
border-bottom: 1px solid #a5cf4c;
margin-top: 0.5em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Anchor with text -->
<a href="#">test</a>
<!-- Anchor with image -->
<a href="#">
<img src="http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png"/>
</a>