Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created January 6, 2018 01:42
Show Gist options
  • Save rg3915/d18399b3fbbd2ba72d8367bdb5dea415 to your computer and use it in GitHub Desktop.
Save rg3915/d18399b3fbbd2ba72d8367bdb5dea415 to your computer and use it in GitHub Desktop.
Percorrendo todos os tr de uma tabela e identificando o último elemento, e transformando a tabela em campos editáveis.
$(function() {
// Edit money
$('.money-edit').on('click', function() {
let obj = $(this).closest('tr').children('td')
// get the length of array (obj)
let totalLen = obj.length
obj.each(function(i, e) {
var item_v = $(this).text()
if (i < totalLen - 1) {
$(this).empty()
$(this).append('<input type="text" style="width:7em" value="' + item_v + '" />')
}
});
});
// Delete money
$('.money-delete').on('click', function() {
let url = $(this).data('url')
let $this = $(this)
$.get(url, function(data) {
$this.parent().parent().remove()
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment