JavaScript counter
Each specific action is performed in JavaScript, for example:
<script type="text/javascript">
$(function() {
$('#typing').keyup(function () {
switch($(this).val()) {
case 'containment':
// HERE
break;
}
});
});
</script>
inside // HERE will be where the counter was created. Then add 1 each time a “containment” case is executed, if it is not already running. So if I run the containment case once, it adds. If I run it again ... it will not - let's see what I'm talking about?
You must determine the counter before starting the count. Then you can add to it later, for example:
<script type="text/javascript">
var count = 0; //(or any number you need)
$(function() {
$('#typing').keyup(function () {
switch($(this).val()) {
case 'containment':
count++;
break;
}
});
});
</script>
/ $('#typing').
:
var count = 0;
$('#typing').keyup(function () {
switch($(this).val()) {
case 'containment':
// Will only run if the element does NOT have the containment class
if(!$(this).hasClass('containment'){
// Add containment class
$(this).addClass('containment');
// Counter
count++;
}
break;
}
});