Click event is not working

1

I'm trying to create a dynamic object for a click event.

Each time a page loads, the data that is saved in the database will be filled in on the front.

The click event has the same rule as the event that checks if the element is checked as the page loads.

var teste = {
    testando: function(element){
        $(element).on("click",function(){    
            var valor = $(element + ":checked").val();
            this.uai(valor);    
            alert("teste");
        });

        if(($(element)).is(":checked")) {
            var valor = $(element + ":checked").val();
            this.uai(valor);
        }
    },
    uai : function(valor){
        //faz algo com o valor, como por exemplo: deixar uma div invisível ou não            
    }
};


$(document).ready(function(){
      $(".radio1").get("2").checked = true;
    teste.testando("[name='radio1']");
});

jsfiddle: link

    
asked by anonymous 29.02.2016 / 17:39

1 answer

0

See if I get it right:

var teste = {};

teste.uai = function(valor){
         alert(valor);            
    };

teste.testando = function(element){    
        if(($(element)).is(":checked")) {
            var valor = $(element + ":checked").val();
            this.uai(valor);
        }
    };

$(document).ready(function(){
      $(".radio1").get("2").checked = true;
    teste.testando(".radio1:checked");
    $(".radio1").on("click",function(){                 
        var valor = $(".radio1:checked").val();
        teste.uai(valor);    
                alert("teste");
    });
});

Fiddle: link

    
29.02.2016 / 17:53