-1

I have the following simple index.jade:

input#elem1
'then I need the following:'
if #elem1.val()='A' then
    label#elem2 input=A

I know I can do this in my js file, but I was looking for a simpler solution using Jade only.

avalanche1
  • 3,154
  • 1
  • 31
  • 38

2 Answers2

1

No, I'm afraid this isn't possible in Jade. Jade is a templating language, it produces the HTML before rendering. Whatever if/else logic that you put in Jade only determines whether something will be rendered or not.

In another sense, it's not dynamic. Your if #elem1.val()='A' would have no meaning because at the time of converting Jade to HTML, #elem1 wouldn't have a value. And by the time it's rendered so it could have value, it's too late for Jade to do anything about it. It's fundamentally not possible.

I hope that makes sense. You might wanna look into what a templating language actually is: What is a templating language?

Community
  • 1
  • 1
laggingreflex
  • 32,948
  • 35
  • 141
  • 196
0

It seems there's no way to do this w\o JS. Here is the closest solution - from ForbesLindesay

avalanche1
  • 3,154
  • 1
  • 31
  • 38