Here is a code:
<input type="button" id="array[1]" value="Value1" />
<input type="button" id="array[2]" value="Value2" />
<input type="button" id="array[3]" value="Value3" />
And I want to do something like that:
$('#array').click(function() {
id = this.id;
$.ajax({
here goes type, url, data and else
});
})
I want to id add array’s number. For example, if I click button where id is array[3] so id gets value of 3 in Jquery’s function. Hope you got what I mean.
First of all you should not be using
[]in id values … onlya-zA-Z0-9-_.:look at the html ID attribute for more info on the specs..
you should name them something like
id_1and extract the number with regular expressions like the other answers suggest…(remember that you cannot start the id value with a number only a-zA-Z)