pass a variable to a url

1

 $(document).ready(function () {
var codigo = "abC";
});
<a class="btn btn-default" href="/meuApp/pagina?codigo=" + codigo +  >Cancelar</a>

Do not even open my page that I put this to. What am I missing?

    
asked by anonymous 04.04.2017 / 19:09

1 answer

3

You can not use the variable this way in your HTML, JavaScript will not be interpreted within your HTML element.

You can do the following:

<a class="btn btn-default custom-url" href="#" >Ver</a>

     $(document).ready(function () {
        $('.custom-url').attr('href', '/meuApp/pagiba?codigo=SEUCODIGO');
});
    
04.04.2017 / 19:22