I have a% d of% and there is .cx-single
in it, I would like to display this <h4>
only when it has a link. How do I do this in jQuery?
I have a% d of% and there is .cx-single
in it, I would like to display this <h4>
only when it has a link. How do I do this in jQuery?
You can do this with just one line of code using .has()
to detect if the h4
element has a link / tag ( <a>
), and leave it already hidden previously with a display:none;
in the CSS code as follows:
$('.cx-single h4').has('a').css('display', 'block');
.cx-single h4 a.link {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="cx-single">
<h4><a class="link">Insira o Link Aqui</a></h4>
<h4>Insira o Link Aqui</h4>
</div>
As you can see the second link is not displayed because it does not contain any element with the tag <a>