G
G
Good Man2016-05-05 10:20:21
Pug
Good Man, 2016-05-05 10:20:21

How to add a class to only the first tag in a jade-generated list?

Good afternoon!
There is a jade code:

nav.main-nav
      each val in ["Journal", "About", "Work", "Contact"]
        a(href="/").main-nav__item= val

How do I add a separate class to just the first link using jade?
Is it possible at all or is it easier to do with scripts in this case?
Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-05-05
@AtriSimone

each val, index in ["Journal", "About", "Work", "Contact"]
  - var class = 'main-nav__item';
  - class += index === 0 ? ' special' : ''
  a(href="/", class="#{class}")= val

R
Roman, 2016-05-05
@r_zaycev

nav.main-nav
  - var first = true;
  each val in ["Journal", "About", "Work", "Contact"]
    - var cn = '';
    - if(first) cn = 'foo';
    a(href="/", class = cn).main-nav__item= val
    - first = false;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question