11
I would like to use a button to mark/uncheck checkbox. I have this button that calls a function, look:
<button
class='btn btn-large'
type='button'
title='Todos'
id='todos'
onclick='marcardesmarcar();'>
<i class='icon-large icon-ok'></i>
</button>
The function:
function marcardesmarcar(){
$('.marcar').each(
function(){
if ($(".marcar").prop( "checked"))
$(this).attr("checked", false);
else $(this).attr("checked", true);
}
);
}
The checks are that way:
<input type='checkbox' class='marcar' name='check[]'/>
This script makes it right the first time, but the second time it does nothing.
If I’m not mistaken, the attribute
checked
HTML (which corresponds to.attr("checked")
) leaves the box marked independent of the attribute value only because the attribute is declared. I think<input type="checkbox" checked="false" />
tag line.– dang
It would be nice if you evaluated the best answer to give the Accept, ("answer accepted" sign, in green) and then applied in the chosen answer, only once. It must be the third time I enter here and your "Accept" has moved. See more on this link: How and why to accept an answer
– Bacco
I endorsed as the best the answer of Anderson Pierok, but thank you for the warning, I will be more prudent in evaluating and only after selecting the best answer.
– adventistapr