Change HTML code via jQuery

1

I'm trying to insert the following code on this page to be able to change the text that appears when the client subscribes to the modal newsletter , which appears when the client is about to leave the page:

$(document).ready(function(){
    $('#btn-cadastre').on("click", function() {
        $('#modal_body_popup.modal-body-center .content-popup .newsletter-send').html('<i class="fa fa-check-circle"></i> Cadastro realizado com sucesso. Compre qualquer produto, seu cupom da <strong>Corda de Pular</strong> está garantido até o final da compra.');
    });
});

Unfortunately, I do not know why, it's not working. I've tried it in many ways and nothing. I would like some help to solve this:)

PS: I'm using Tampermonkey v4.5 to run the tests.

    
asked by anonymous 09.05.2018 / 21:37

1 answer

1

First I would put an alert inside the click function to check if it is actually entering the function.

$(document).ready(function(){
    $('#btn-cadastre').on("click", function() {
        alert("Entrou");
    });
});

If you are entering the function, it is necessary to check if the selector is correct. In your case, you have the # modal_body_popup.modal-body-center that is the parent of .content-popup that is the parent of .newsletter-send (not necessarily 1st grade)

If you are not entering the function and the # btn-register selector is correct, maybe # btn-register is an item that was inserted into the page via javascript after the creation of your click function. In this case one of the solutions is to use the "$ (document) .on":

$(document).ready(function(){
    $(document).on("click","#btn-cadastre", function() {
        $('#modal_body_popup.modal-body-center .content-popup .newsletter-send').html('<i class="fa fa-check-circle"></i> Cadastro realizado com sucesso. Compre qualquer produto, seu cupom da <strong>Corda de Pular</strong> está garantido até o final da compra.');
    });
});
    
09.05.2018 / 21:45