How to remove added values with javascript
$('#toggle1,#toggle2,#toggle3').click(function() { toggleText(this.innerHTML); }); function toggleText(text) { $(".text").each(function() { $(this).val($(this).val().split( /circle|square/ ).join("") + " " + text); //remove existing circle or square and then add text }); }