Last active
August 29, 2015 13:56
-
-
Save vishaltelangre/9070280 to your computer and use it in GitHub Desktop.
jquery on 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
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.7.2/mustache.min.js"></script> | |
<div class="parent"> | |
<div class="child"> | |
<div class="widget"></div> | |
<button>Display Current Value</button> | |
</div> | |
<div>Current value of widget is: <span class="currentVal">N/A</div></div> | |
</div> | |
<script type="text/mustache" id="widgetTemplate"> | |
<hr> | |
<h1>Blah Widget</h1> | |
<div>Current value of widget is: <span class="widgetVal">{{val}}</span></div> | |
<div>Rendered for {{times}} times.</div> | |
</script> |
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
var widgetVal = 99999, | |
times = 0; | |
$('.parent').on('click', '.child button', function(e){ | |
e.preventDefault(); | |
var currentVal = $('.child .widgetVal').text(); | |
$('.parent .currentVal').text( currentVal ); | |
}); | |
setInterval(function(){ | |
var tmpl = $('#widgetTemplate').html(); | |
widgetVal = widgetVal - 1; times = times + 1; | |
var compiledTmpl = Mustache.render(tmpl, {val: widgetVal, times: times }); | |
$('.child .widget').html( compiledTmpl ); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment