1
Is it possible to create a conditional by assigning the conditional within a value? I did it the way I did it, but it didn’t work:
HTML
<input type="radio" name="pg1" value="SIM"> TESTE <BR/>
<input type="radio" name="pg1" value="NÃO"> TESTE 2
<div id="esconde">
<p>NADA</p>
</div>
JAVASCRIPT
$(document).ready(function(){
$("[name='pg1']").click(function(){
var valor = $(this).val();
divShowOrHide({
//valorEscolhido: valor,
condicional: valor+" === SIM",
hideDiv: "#esconde"
});
});
});
function divShowOrHide(obj){
//alert(obj.condicional);
if(obj.condicional){
$(obj.hideDiv).show();
} else {
$(obj.hideDiv).hide();
}
}
o Jsfiddle: http://jsfiddle.net/vgh42jqb/
I recommend reading of What is the difference between . on("click", Function() {}) and . click(Function() {})?
– Guilherme Lautert