A
A
Anton2020-04-21 19:27:48
JavaScript
Anton, 2020-04-21 19:27:48

Why is the checked attribute not being set?

Added a spoiler, by clicking on the label, a div opens. Stopped checking radio. in a loop, loaded with ajax
.spoiler {display:none;}

<div class="box">
 <label class="spoiler_links">
 <input class="linkradio" type="radio" name="postamat">
 </label>
<div class="spoiler"><?=$arr['spoiler'];?></div>
</div>

on the page where the result comes from
$(document).on('click','.spoiler_links',function (e) {
$("div[class^='spoiler']").hide('normal');
$(this).parent().children('div.spoiler').toggle('normal');
return false;
 });

Added in different ways to the code, like this. But either toggle starts working twice, or the last radio is checked, or nothing happens.
$('.linkradio').attr('checked',true);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-21
@anton99zel

because

return false;

Returning false from an event handler set via jquery causes the default action to be cancelled. In this case, a click on an input.
Hang the handler on input instead of label and listen for change instead of click.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question