Pregunta

I'm filling my WebApp (Django) template variables in html body data attributes. So that I can access them later through Javascript:

<body data-node_ip={{NODE_IP}}>
<body data-node_port={{NODE_PORT}}>

Later in the Javascript code, I'm accessing the variables through jQuery's data method:

var connection = $("body").data("node_ip") + $("body").data("node_port")

This works well with all modern browsers (IE10, Chrome, FF).

Problem:

However it doesn't work with IE9 or older. IE9 only stores one single value associated to the tag.

My question:

How do I store these template variables in my HTML document (without using Javascript / jQuery) so that they are also accessible down to IE9?

Thanks!

¿Fue útil?

Solución

This doesn't seem to be valid. You can only have one body element. But you can and should put all the attributes on that single element:

<body data-node_ip={{NODE_IP}} data-node_port={{NODE_PORT}}>

Otros consejos

Why don't you assign them different ids and access them like this:

var connection = $("#body1").data("node_ip") + $("#body2").data("node_port")
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top