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