Error with a Jquery and html alert

1

I'm making an alert with jquery .... the function of it is to show the user the error and depending on the action lead to a next page ... well I already tested it and the error is in jquery because when I put the alert in pure html it appears perfectly

Thisexampleabovehashtml...thewayitshouldappear.

Let'sgotothecode

$(document).ready(function(e){varsite={fechar:function(parametro){$('#alerta-preto').fadeOut(2000);$('#alerta-base').fadeOut(2000)location.href="http://www.site.com.br/"+parametro+"";
    }

alerta: function(conteudo,diretorio){
html = '';
html += '<div id="alerta-preto"></div>';
html += '<div id="alerta-base">';
html += '<div id="alerta-topo">Alerta <div id="alerta-fechar" onclick="site.fechar("'+diretorio+'")"></div></div>';
html += '<div  id="alerta-branco">';
html += '<div class="titulo"><b>Ops,</b> Alerta</div>';
html += ''+conteudo+'';
html += '</div>';
html += '</div>';   
$('#alerta-fly').append(html);
}
}
});

+ - so to call

//apenas para mostrar
site.alerta('Dados incorretos.','nao');
//para direcionar
site.alerta('Logado com sucesso.','inicio');

The problem is that it does not work .... I checked this code several times and it's fine to see ...

    
asked by anonymous 25.10.2015 / 22:48

1 answer

0

First, your functions within the site variable can be executed in any context of the site. So you can not restrict it within $ (document) .ready

  

Below is the code for testing

     

Note: I commented the method to direct, to perform the test uncomment the same.

var site = {
    fechar: function(parametro){
        $('#alerta-preto').fadeOut(2000, function (){
                $('#alerta-base').fadeOut(2000, function (){
                    if(parametro != undefined) {
                        location.href="http://www.site.com.br/"+parametro+"";
                    }
                });  
        });
    },
    alerta: function(conteudo,diretorio){
        var html = '<div id="alerta-preto"></div>';
        html += '<div id="alerta-base">';
        html += '<div id="alerta-topo">Alerta <div id="alerta-fechar" onclick="site.fechar("'+diretorio+'")"></div></div>';
        html += '<div  id="alerta-branco">';
        html += '<div class="titulo"><b>Ops,</b> Alerta</div>';
        html += conteudo;
        html += '</div>';
        html += '</div>';   
        $('#alerta-fly').html( html );
    }
}

$(document).ready(function(e) {
    //apenas para mostrar
    site.alerta('Dados incorretos.');
    //para direcionar
    // site.alerta('Logado com sucesso.','inicio');
});
    
25.10.2015 / 23:31