JSFiddle - React, Tailwind, and code Playground
by Pedro Fialho
HTML
<div id="id0_del">Foo</div>
<div id="id1_del">Bar</div>
<div id="id2_del">Baz</div>
CSS
div {
margin: 8px;
padding: 8px;
background: #ded;
}
JavaScript
smth = ['foo', 'bar', 'baz'];
$('div')
.filter(function() {
return this.id.match(/^id\d+_del$/);
})
.click(function() {
let id = this.id.match(/id(\d+)_del/)[1];
$.ajax({
type: 'POST',
url: 'delete.php',
data: {filek : smth[id]},
success: function(html){
console.log(html);
}
});
})