In JQuery
, we have a function called toggle
that allows us to switch between the element to be visible or not. And the toggleClass
function, which allows you to switch between adding a class or not.
$(function () {
$('button').click(function () {
$('div').toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divstyle="display:none">Estou aqui</div>
<button>Click</button>
But I have the need to "put and take" an attribute in the same way that this function does. I want to do this with the required
attribute in input
.
Can you do this in jQuery?