satriabajakan satriabajakan - 1 month ago 7
Javascript Question

Replacing Text "The Map" with Script

I want to change all of the text is "

#
", "
/
", and "
+
" using JavaScript or jQuery.

How to change this to appear on
<div id="results"></div>
?

#
=>
hash


/
=>
or


+
=>
plus


Example:

before:
G#7+


after:
Ghash7plus


and

before:
Fm/Ab


after:
FmorAb


My Code:

<span class="teks">A</span>
<span class="teks">B</span>
<span class="teks">C#</span>
<span class="teks">G#7+</span>
<span class="teks">Fm/Ab</span>

<h3>RESULTS</h3>
<div id="results"></div>

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js' type='text/javascript'></script>

<script>
var textValues = $('.teks').map(function() {
thisCrd1 = $(this).html();
thisCrd2 = $(this).html();
return "<div class='crd_"+ thisCrd1 + "'>"+ thisCrd2 + "</div>";
}).get();

$('#results').html(textValues);
</script>


I have tried many times, but apparently not getting the results I want.

Answer

You can try the below code to replace #, \ and + with corresponding text (provided other code is fine),

var thisCrd2 = thisCrd1.replace("#", "hash").replace("/", "or").replace("+", "plus");
Comments