Created
May 25, 2020 22:22
-
-
Save ianhoffman/e0fef9ea77c2e8e0ff71beb1bc5dc152 to your computer and use it in GitHub Desktop.
JS Template Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<div><h1>Testing...</h1></div> | |
<div class="card-list" id="card-list"></div> | |
</body> | |
<script type="text/template" id="card-list-item"> | |
<div class="card-list-item"> | |
<h2 class="card-title"></h2> | |
<span class="card-subtitle"></span> | |
</div> | |
</script> | |
<script type="application/javascript"> | |
$(document).ready(function () { | |
var $template = $('#card-list-item'); | |
var $html = $template.html(); | |
var cardData = [ | |
{ | |
title: 'foo', | |
subtitle: 'bar' | |
}, | |
{ | |
title: '1', | |
subtitle: '77', | |
} | |
]; | |
for (var i = 0; i < data.length; i++) { | |
var $card = $($html); | |
$card.find('.card-title').text(cardData[i].title); | |
$card.find('.card-subtitle').text(cardData[i].subtitle); | |
$('#card-list').append($card); | |
} | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment