How to get value from a hidden_field_tag using data-id?
<p>How do I get the value of an <code>hidden_field_tag</code> with <code>data-id</code> attribute?</p>

<p><strong>html.erb</strong></p>

<pre><code>&lt;%= hidden_field_tag "data-id" =&gt; 'cart-total', "value" =&gt; "#{total}" %&gt;
#=&gt; &lt;input type="hidden" name="{"data-id"=&gt;"cart-total", "value=&gt;"1"}" id="__data-id__cart-total___value___1__"&gt;
</code></pre>

<p><strong>JavaScript</strong></p>

<pre><code>var cartTotal = $("[data-id=cart-total]").val();
console.log(cartTotal); // undefined
</code></pre>

<p>I do not know the correct way to write this with rails <code>hidden_field_tag</code>.</p>