I have a button and an input field. When I click the button, I want the input field to be populated with some text. And when click the button again, I want the populated text to disappear or become Null.
When I checked online, I could only find links to toggle classes from elements in the list.
How do I achieve this with jQuery?
This is my code so far. I am able to populate the input field with the required value. But I am not able to remove the value when I click the button again.
<button type="button" class="btn btn-outline-primary" id="test-button" data-toggle="button" aria pressed="false" autocomplete="off">
Click Me
</button>
<input type="text" name="test-input" id="test-input" value="">
<script type="text/javascript">
$('#test-button').click(function()
{
$('#test-input').val("Value Populated");
}
)
</script>