0

Is there any specification for "Pass database variables to jQuery via element attribute?"

I've been doing this for a long time:

<script>
   var status = <%= status %>;
</script>

I would much rather do something like this:

<variable data-name="status" data-value="<%= status %>" />

Then get it with jquery:

var status = $('variable[data-name="status"]').attr("data-value");

I would need the element to be hidden from displaying. I know there is a pattern for this, I just don't know what it's called or how to search it.

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424

1 Answers1

1

Have you tried:

<input type="hidden" data-name="status" data-value="<%= status %>" />

KingKongFrog
  • 13,946
  • 21
  • 75
  • 124