jessica
jessica

Reputation: 1687

Similar function as attr() with parameter for callback function

I have a button and an input box. When you click the button, it's suppose to make the input box readonly, before calling a callback function, but the problem is that the attr() in jQuery doesn't have a parameter for the callback function. Is there another jQuery function I can use that basically does the same thing but also have a parameter for the callback function, or is there another way to do this? Thank you.

<button> click me </button>
<input type = "text">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script type = "text/javascript">
    $(function() {
        $('button').click(function(){
            $('input').attr('readonly', 'readonly');
        });
    });     
</script>   

Upvotes: 0

Views: 43

Answers (1)

Diptox
Diptox

Reputation: 1809

$(function() 
{
    $('button').click(function()
    {
        $('input').attr('readonly', 'readonly');
        // Do what you want here
    });
}); 

Upvotes: 2

Related Questions