I have a button which right now is set as a type “submit”. This calls the controller, execute some code and returns back to the view. When I use jquery to hide the button, I see that when I click on the button, what I have hides the button but as soon as the view is returned, the button is not hidden no more. Whereas with type “button”, when I click the button, this hides the button but doesnt execute the code in the controller. Is there a way to hide the type “submit” button so when the view returns, the button is still hidden?
$('#btnAdd').click(function() {
$('#btnAdd').hide();
});
<input type='submit'>creates a button that submits a form to a server and triggers your server code. If you want the button hidden when the page comes back, you need to add logic to your page to do that. How you do this will depend on your server technology (php, .net, etc.).The reason the behavior with
<button>is different is that<button>s don’t submit the form (unless you add more code to make them do that)…so the above mentioned stuff never happens. It’s not so much that a<button>stays hidden as much as the page never changes/reloads. If you added code to the<button>to make it refresh the page, it’d reappear, too.