I am trying to implement a revert() option inside my website but the implementation does not show any result. This is what I have so far:
$('.harm > text:nth-child(1) > tspan:nth-child(1)').each(function(){
$this = $(this);
// Store the current text in data old.
$this.data('old', $this.text());
});
$('#revert').click(function(){
$('.harm > text:nth-child(1) > tspan:nth-child(1)').each(function(value, index){
$this = $(this);
// Fetch the old text from data.
var old = $this.data('old');
// Set the text on the element.
$this.text(old);
});
});
and a button with the id revert But it does not revert back to original text, after editing the text with the following code:
function Akoord() {
var replacements = {
'A': 'F#', 'A#': 'G', 'Bb': 'G', 'B': 'G#', 'C': 'A', 'C#': 'A#',
'Db': 'Bb', 'D': 'B', 'D#': 'C', 'Eb': 'C', 'F': 'D', 'F#': 'D#',
'Gb': 'Eb', 'G': 'E', 'G#': 'F', 'Ab': 'F'};
$('.harm > text:nth-child(1) > tspan:nth-child(1)').text(function(i, text) {
return text.replace(/[A-G](b|#)?/g, function(m) { return replacements[m]; });
});
}
The text is being edited but can't revert it back by pushing the button, someone know a solution for this?