The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Mask the item if it is empty

View previous topic View next topic Go down

Solved Mask the item if it is empty

Post by Milouze14 on 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
Forumember

Male Posts : 35
Reputation : 2
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 on 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Milouze14 on 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
Forumember

Male Posts : 35
Reputation : 2
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 on 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Mask the item if it is empty

Post by Milouze14 on 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
Forumember

Male Posts : 35
Reputation : 2
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 on 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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