I have different inputs
type checkbox
with a value ="{"valor":"1"}"
or value ="{"valor":"0"}"
. For example:
<input type="checkbox" id="switch" name="switch" value ="{"valor":"1"}" ">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"0"}" ">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"0"}" ">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"1"}" ">
What I want to do is go through and add the attribute checked
if this is a input
with value {"valor":"1"}
otherwise the attribute will not be added. For example:
<input type="checkbox" id="switch" name="switch" value ="{"valor":"1"}" checked">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"0"}" ">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"0"}" ">
<input type="checkbox" id="switch" name="switch" value ="{"valor":"1"}" checked">
This is my function but it changes all the inputs:
$('#switch').each(function(){
if ($(this).val() == '{"valor":"1"}' )
{
$('#switch').attr("checked",true);
}
else{
$('#switch').attr("checked",false);
}
});
I know that it changes all the inputs because they have the same id ... but that id can not change it, will there be another way to do it? ...