0
Good afternoon! I don’t have much experience with jquery, so I’m having problems. I’m creating a new element when I click on a button.
$('#tbody_6').append('<tr id="'+token+'"><td><input required id="time_ini_6['+token+']" class="form-control" type="time" name="time_ini_6['+token+']"><input required class="form-control" type="time" id="time_max_6['+token+']" name="time_max_6['+token+']"><input id="price_6['+token+']" name = "price_6['+token+']"type="text" class="form-control" placeholder="Preço" value="" autofocus><button class="btn btn-md btn-alt btn-danger" id="minus_'+token+'" onclick="removePeriod(this)" type="button"><i class="fa fa-minus-circle"></i></button></td></tr>');
Creating something more or less like this:
After that I wanted to call a function to return the id of this my removal button.
function removePeriod(elem){
var id = $(elem).attr("id");
console.log(id);
}
That function
removePeriod
is defined in the global scope? It seems to me that your element is not able to see the function.– Andre
It was set within $(Document). ready(Function().... Thus, it could not find. I just left inside the script tags and took it from inside Document.ready and it worked for me. Thanks
– Matheus Alves