I have some code listening for a onclick event on a particular radio button/label. However the click on the label/radio "doubletaps" the click event and bugs out my code. - the ".custom_block" appears and disappears, it only appears and stays visible if I press the same radio button the second time. I've tried prevent default event - it works, but then the radio button is not selected. Whats the best solution in this case?
$('#trigger').live('click', function (event) {
clicked_id = event.target.id;
clicked_class = $('#' + event.target.id).attr('class');
if(event.target.id == 'flat.flat' || event.target.id == "flat\\.flat"){
console.log("GOOD");
$(".custom_block").css("display", "block");
//event.preventDefault(); // this works - but the radio itself is not checked after the click.
}else{
console.log("BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD");
$(".custom_block").hide();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<div class="surrounding-div">
<div id="trigger">
<div class="radio-input radio">
<input type="radio" name="shipping_method" value="flat.flat" id="flat.flat" checked="checked" data-refresh="5" class="styled">
<label for="flat.flat" data-label="flat.flat">
<span class="text">some text</span><span class="price">1.90 €</span></label>
</div>
</div>
<div class="custom_block">
some content I want visible.
</div>
</div>