I have few buttons of which each button is assigned a class with a number. When I click each button, the number is submitted in an input. If I double click that button, I want that number/value to get deleted from the input but only that number.
Here is my example: http://jsfiddle.net/HC5W7/
and this is my code:
$("div").live('click',function() {
var a = $('input').val();
var b = $(this).attr('class')
var c;
if ( $("input").val().indexOf(b) !== -1 ) {
// the code to delete the specific number
return false
}
if ($("input").val().length > 0) {c = ","}else{ c = ""}
$('input').val(a + c + b);
});
A simple replace with a regex should do the trick:
Edit: link to JSFiddle Fork: http://jsfiddle.net/g6Hn7/