I would like to switch a class when I click on a div.
{{ form_row(onboardingChoicesChild.children.0, {'label_attr':
{'class':'textselection'}}) }}
The following form_row has a class "textselection", and I would like to toggle it. I know how to toggle class in javascript with div but I don't know how to toggle these datas.
Twig is just making templating,
In your example, when you write $(this).hasClass('selected') you try to check if <div class="selection"> has 'selected' class
In my opinion you should try this:
if ($(this).first().hasClass('selected')) {
$(this).first().removeClass('selected');
}
else {
$(this).first().addClass('selected');
}