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.
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.
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?
It seems there's no way to do this w\o JS. Here is the closest solution - from ForbesLindesay