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.

1
  • I like the most the way you were doing it for a long time :) Apr 6, 2013 at 1:07

1 Answer 1

1

Have you tried:

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

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.