Send variable via Jquery function

1

I'm learning Jquery and catching it not even a convict.

I created a function in the js file like this:

$(function abrir_qd1(variavel){
$(this).click(function(){
            $("#quadro1").load('arquivo.php?v=' + variavel); //carrega conteudo
});

});

and the function is called via an html link:

<a onclick="abrir_qd1('var_enviada')" class="list_nome_aguard">click aqui</a>

And through an alert I discovered that the problem that varivel arrives in the function like this:

arquivo.php?v=function (a,b){return new p.fn.init(a,b,c)}

I'm not sure how to handle it here.

Thank you in advance

    
asked by anonymous 22.11.2017 / 10:49

1 answer

0

There are some patterns together there .... the first one you will use when you want the function to be called in the page load, without anyone's action, then you do it like this:

$(function(){
    alert('carregou');
});

For you to declare a function, you only declare the name and variable, so it waits to be 'called' by some action, in this case you declare it in the onclick of the link like this:

function abrir_qd1(variavel){
       $("#quadro1").load('arquivo.php?v=' + variavel); 
}

There is also the possibility of using jquery to have a selector and an action and every time it finds the selector and the action it executes, without you needing to use the onclick action for example.

$(".algumaClasse").click(function(){
      $("#quadro1").load('arquivo.php?v=' + variavel); 
});

If you put the 3 together, it will not go anywhere like this ...

    
22.11.2017 / 11:11