0

I'm using the small module Link Badges to display a badge with the amount of flagged nodes next to a link to the View in question. It works great and I've styled the badge to my needs. This is the current HTML code:

<a class="menu__link menu__link link-badge-wrapper">
  <span class="link-badge-text">My View</span>
  <span class="link-badge-badge-wrapper">
    <span class="link-badge link-badge-menu_badges_execute_view">0</span>
  </span>
</a>

Now, I'd like to display the badge a little bit differently (other colors etc.) when the value is 0. I thought about doing this by adding a new CSS class link-badge-zero to the value.

<a class="menu__link menu__link link-badge-wrapper">
  <span class="link-badge-text">My View</span>
  <span class="link-badge-badge-wrapper">
    <span class="link-badge link-badge-zero link-badge-menu_badges_execute_view">0</span>
  </span>
</a>

How can I achieve this?

0

Thanks to @Ramis Wachtler at Stack Overflow, I got the following JQuery code:

if($(".link-badge").text() == "0"){
    $(".link-badge").addClass("link-badge-zero");
}

Possible easier solutions are always welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.