Heather XM Heather XM - 1 year ago 404
Javascript Question

Jade -- how can i get a value from id

in jade file

h1 #score

from above content, it displays value 65. Namely, I can get the value 65 from id score.

Now how can I get value from #score?

I tried

var = document.getElementById("score").text();

but it shows error : Cannot read property 'getElementById' of undefined

Answer Source

Jade files are compiled by JavaScript (Yes, there are some other compilers written in other languages as well). Since Jade files are usually compiled on server or in a building environment, you can't directly use DOM APIs in these files that way.

You should wrap your code with a script tag, so the script is executed on the browser and not during the compiling process. "Cannot read property 'getElementById' of undefined" means that you are using DOM APIs directly in your Jade files and these APIs do not exist in that environment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download