As I execute two events $ (". example"). click (function () {in this query, it is possible to assign two selectors to execute the same event.
To be more exact I can execute click event to remove detail and add. that are in one and not separately
Normally jQuery associates the events when the page loads (the document.ready).
If you create new elements after running the document.ready they will not have the associated events. You will have to associate them again.
For that reason I put a oneclick inside another because the before adds a new html to the sun. but if I put them separately the variable that comes from before the event below does not hold it because effectively when the page starts the data does not exist. how do I solve the problem thanks
Can you give me an example?
$(".agregar").click(function(){
codigoproducto =$(this).parent().parent().children(".codigoproducto").html();
$(".agregarproducto").before(' <tr class="trjson"><th class="codigoproducto">'+codigoproducto+'</th></tr>');
$(".eliminardetalle").one('click', function() {
$(this).parent().parent().remove();
codigoproducto=$(this).parent().siblings(".codigoproducto").html();
console.log(codigoproducto);
});
});
//////////////////////////////////////////////////////////////////////////
$(".agregar").click(function(){
///agregar carga variable
codigoproducto =$(this).parent().parent().children(".codigoproducto").html();
///before la asigna al html
$(".agregarproducto").before(' <tr class="trjson"><th class="codigoproducto">'+codigoproducto+'</th></tr>');
$(".eliminardetalle").one('click', function() {
////recoge variable del html que fue asigando del before
$(this).parent().parent().remove();
codigoproducto=$(this).parent().siblings(".codigoproducto").html();
console.log(codigoproducto);
});
});