I'm trying to add buttons dynamically with Jquery, now for each button, I want to perform a different action, how can I achieve it? Each couple of buttons will toggle after the action is performed e.g.
- show 1 after click becomes hide1
- show 2 after click becomes hide2
- show 3 after click becomes hide3
I created a JSFiddle to display what I achieved so far.
var randomMeetings = Math.floor(Math.random() * 10) + 1;
for(var i = 0; i < randomMeetings; i++){
var expandClient = '<button type="button" class="hide_client" id="_hide_'+ i +'"><i class="fa fa-plus-square-o"></i></button><button type="button" class="show_client" id="_show_'+ i +'"><i class="fa fa-minus-square-o"></i></button>'
$('#myButtons').append(expandClient);
}
for (var i = 0; i < randomMeetings; i++){
$('#_show_'+i).click(function() {
$('#_hide_'+i).toggle();
});
$('#_hide_'+i).click(function() {
$('#_show_'+i).toggle();
});
}