I am developing in PHP and am using some html wrappers (styled divs) around dynamic/variable content. In other words, I'm using a standard template multiple times and filling it with different HTML, creating similar looking "modules". I also am using jQuery to dynamically update the content based on user interaction. Each module requires some extra information to tell jQuery how to process the user interaction. I have been waffling between using microdata or data attributes to accomplish this. Examples:
<script>
$(document).ready(function() {
eval($(".wrapper").children("meta[itemprop=userDoesSomething]").attr("content"));
});
</script?
<div itemscope class="wrapper" id="module1">
<meta itemprop="userDoesSomething" content="alert('Microdata is better!');">
Module-specific content
</div>
or
<script>
$(document).ready(function() {
eval($(".wrapper").data("userDoesSomething"));
});
</script>
<div class="wrapper" id="module1" data-userDoesSomething="alert('Data attributes are better!');">
Module-specific content
</div>
Both accomplish the same thing, but with microdata, I don't have to insert an attribute into the wrapper's tag. I can just include the "data" inside the wrapper using a meta tag, keeping the wrapper template intact. I also realize the data attribute is probably more appropriate as microdata is really meant for typed data, but in this case, it is more convenient. Any thoughts on which is better in the long run?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…