I have an array of data that I will echo on the page using PHP, and I want JQuery to be able to parse it. However, I do not want the data to be visible to the user. I have for example:
<div id="data-1">
<span id="width">5</span>
<span id="height">10</span>
<span id="depth">15</span>
</div>
<div id="data-2">
<span id="width">10</span>
<span id="height">20</span>
<span id="depth">30</span>
</div>
I am wondering if I should store data in passes this way and then in jQuery, hiding them when loading and playing with data, getting range values later:
$(document).ready( function() {
$("#width, #height, #depth").hide();
$("#data-*").click(function() {
var width = $("#width", $(this)).text();
var height = $("#height", $(this)).text();
var depth = $("#depth", $(this)).text();
});
});
Is this the most efficient way to store data on a page? Should I use hidden inputs instead, or are there other ways to do this?
source
share