Hello, I have the following code to create two buttons (one on the left one on the right) for each texbox on the page. Idea is to make an increment/decrement textbox. Code works fine with one textbox but with 2 or more every button increment/decrements all textboxes.
Any idea how to create buttons on the fly and attach them to a textbox for increment/decrement?
jQuery.fn.incrementer = function() {
this.val(0);
this.before("<input class='incrementer_minus' type='button' value=' - '/>");
var myobj = this;
$(".incrementer_minus").live('click', function(){
$(myobj).val(parseInt(JQ(myobj).val()) - 1);
});
this.after("<input class='incrementer_plus' type='button' value=' + '/>");
$(".incrementer_plus").live('click', function(){
$(myobj).val(parseInt(JQ(myobj).val()) + 1);
});
}
JQ("#increment").incrementer();
JQ("#increment2").incrementer();