Enable / Disable input per id

1

I have two inputs, when I automatically click they become readonly, I'm doing so:

<script>
    $(document).on('click', '#outros,#txtOutros', function() {
        $('#outros').attr('readonly', true);
        $('#txtOutros').attr('readonly', true);
    });
</script>

But I want you to click on the input # others only it readonly and vice versa.

    
asked by anonymous 10.12.2015 / 16:49

3 answers

4

Hello,

Do so

<script>
    $(document).on('click', '#outros, #txtOutros', function() {
       $('#txtOutros, #outros').attr('readonly', false); 
       $(this).attr('readonly', true);
    });
</script>
    
10.12.2015 / 16:58
2

jQuery

10.12.2015 / 16:54
1

Would not it be better to use the class attribute? For example class="bt" :

$(document).on('click', '.bt', function() {
    $('.bt').attr('readonly', false); 
    $(this).attr('readonly', true);
});
    
10.12.2015 / 17:42