четверг, 2 июля 2015 г.

Change label text on div click depending on checkbox value

Изменение текста в label в зависимости от checkbox при клике на div


Javascript 
$(document).ready(function () {
    $(".markerDiv").click(function () {
        var checkBox = $('input[name=markerType]', this);
        $(checkBox).prop('checked',           !checkBox.is(':checked'));
        if ($(checkBox).is(':checked')) {
            $("#markerLabel").text("en");
        } else {
            $("#markerLabel").text("ge");
        }
    });      
});

HTML
<div class="markerDiv" id="maker_school">
<div >
<label class="marker_label" for="kbd-switcher" id="markerLabel">Click here</label>
</div>
<input id="kbd-switcher" type="checkbox" class="marker_ckeckbox" name="markerType" style="display: none;"  />
</div>

And don't forget to include jquery library. I'm working with jquery_1.7.1.min.js

See the example

Комментариев нет:

Отправить комментарий