The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Mask the item if it is empty

2 posters

Go down

Solved Mask the item if it is empty

Post by Milouze14 November 4th 2015, 4:50 pm


Hi to all of you,
Ange Tuteur if you pass by here Hello
I want to hide this item ( sous_forum_s and ouverture_sousforum_s ) if it is empty,
the effect is for the sub forums.


Here is the HTML code

Code:
<div align="left" class="sous_forum_s">
  <span class="sforum_s">
    <span>
{catrow.forumrow.L_LINKS}{catrow.forumrow.LINKS}
{forumrow.L_SUBFORUM_STR} {forumrow.SUBFORUMS}
    </span>
  </span>
<span class="ouverture_sousforum_s">◄</span></div>
</div>





thank you in advance .

a++
Milouze14
Milouze14
Forumember

Male Posts : 59
Reputation : 18
Language : French
Location : Vendée

http://www.milouze14.com/

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Ange Tuteur November 4th 2015, 5:11 pm

Hi @Milouze14,

You want to hide the element when there are no sub-links, correct ? Smile

If so, this JavaScript should do the trick :

Modules > JS codes management > New

Placement : In the homepage
Code:
$(function() {
  for (var a = $('.sous_forum_s'), i = 0, j = a.length; i < j; i++) {
    if (!a[i].getElementsByTagName('A')[0]) {
      a[i].style.display = 'none';
    }
  }
});

In some instances you can also use the CSS
Code:
:empty
pseudo-selector(link), however I don't think that would be applicable here.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Milouze14 November 4th 2015, 5:18 pm

Grrr, it's been two hours that I get tired and you in a few seconds, you released me .
Yes I tested with CSS selector, but nothing concrete.
Thank you a lot

a++
Milouze14
Milouze14
Forumember

Male Posts : 59
Reputation : 18
Language : French
Location : Vendée

http://www.milouze14.com/

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Ange Tuteur November 4th 2015, 5:27 pm

You're welcome ^^

Yes, the
Code:
:empty
selector is pretty useless on the forums, so it's better to go with JavaScript. With JS you just need to loop the elements to see if they have the children you want. Here's the same code, but entirely in jQuery :
Code:
$(function() {

  $('.sous_forum_s').each(function() {

    if ($('a', this).length == 0) {
      $(this).hide();
    }

  });

});

Code:
$('a', this).length
refers to the amount of <a> elements ( or sub-links ) that
Code:
.sous_forum_s
contains. If it's equal to 0, we hide the element. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Milouze14 November 4th 2015, 5:33 pm


Oh thank you for these explanations as being self-taught in this area, I still have just learned something real good, thank you for the time you spend to help people like me Very Happy

thank you again Ange Tuteur thumright .

a++
Milouze14
Milouze14
Forumember

Male Posts : 59
Reputation : 18
Language : French
Location : Vendée

http://www.milouze14.com/

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Ange Tuteur November 4th 2015, 5:51 pm

No problem, if you have any questions you can always ask me. Mr. Green

Topic archived

Have a great day. Beer
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum