1
I’m trying to create a dynamic object for a click event.
Every time a page is loaded, the data that is saved in the database will be filled in at the front.
The click event has the same rule as the event that checks if the element is checked as soon as the page is loaded.
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: https://jsfiddle.net/9rmu2jpw/2
is that, but I wanted to do the event by clicking inside the object, would save an encoding save (ie, would just call the "test.testing" by passing the element...)
– carlos
The way you did the click event will only fire when the first element that was loaded on the page as checkado is clicked. That’s what you want ?
– Joao Paulo
i wanted this event to always be triggered when the element was clicked, but how do I work using a click event inside the object?
– carlos
When you use inside the object, you are always using the same selector, which is "[name='radio1']", which you call 1 time when loading the document (within Document.ready). To always grab the element that is clicked you can not put this event click inside the object.
– Joao Paulo