Since I'm running two $(".example").click(function(){ events on this query, it's possible to assign two selectors to it to run the same event.
to be more exact I can execute click event to remove detail and add. that they are in one and not separately
Normally jQuery binds the events at the end of the page load (the document.ready ).
If you create new elements after executing 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 dom. but if I put them separately, the variable that comes from the before event below does not grab 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);
});
});
So:
NOTE EDITION: Rereading what you ask, I think I have answered something that is not, I'll leave it anyway just in case if it is what you ask. In the other case, it would be like this:
With this method, even if the DOM is loaded, it will send the event to the selector element and you save generating events within events.