Reputation: 409
I have a website into modx cms, I'm trying to remove or hide a div when into that div there is no tag. How can I do this?
I tried this but no luck:
jQuery(function($) {
if ($(".pages a")) {$(".pages").remove();}
});
< div class="pages">[+previous+] [+pages+] [+next+]< /div>
Upvotes: 0
Views: 134
Reputation: 167250
if ($(".pages a").length == 0) {
$(".pages").hide();
}
And when the links are there, or you making an AJAX call, do this:
$(".pages").show();
Upvotes: 0
Reputation: 879
another shorter answer would be
$('.pages:not(:has(>a))').css("display", "none");
Upvotes: 1
Reputation: 12693
I'm not sure if this is what you want:
$(function($) {
$(".pages").each(function(){
if(!$(this).find('a').length)
$(this).remove();
});
});
Upvotes: 0
Reputation: 4907
If you are trying to check if the <a>
tag exists inside the div then you could try:
if($(".pages a").length == 0) {
// links don't exist
$(".pages").remove();
} else {
// links exist
}
Upvotes: 1