Last active
April 7, 2017 07:51
-
-
Save makgithub/bb07dd940b8b4488118818f6c94f981b to your computer and use it in GitHub Desktop.
Fill template using jquery. Defining a HTML template to append using JQuery
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> | |
<head> | |
<title>Modular Design Pattern</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<div>TODO write content | |
<input type="button" name="button" value="buttonclick" id="buttonclick"/> | |
<div id="target"></div> | |
</div> | |
</body> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script> | |
$(document).ready(function () { | |
//Clone the template | |
var template = $('#hidden-template').html(); | |
$('#buttonclick').click(function () { | |
//Clone the template | |
var item = $(template).clone(); | |
//Find the | |
$(item).find('.first').html("First"); | |
//Change 'bar' to '-Bar' | |
$(item).find('#bar').html("-Bar"); | |
//Append to the source | |
$('#target').append(item); | |
}); | |
}); | |
</script> | |
<script id="hidden-template" type="text/x-custom-template"> | |
<tr> | |
<td class="first">Foo</td> | |
<td id="bar">Bar</td> | |
<tr> | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jquery template