javascript - Change button attr on keyup dynamically -
i'm working on search, , toggling input field search icon. default icon wrapped in button element type button not submit form.
i want validate if text has been entered , change type of button submit on next click of icon.
here's code far
// mobile search ui $(document).ready(function() { $('.mobile-btn-search').click(function(){ $('.mobile-input').toggle('slow'); }); $('.mobile-input').keyup(function(){ if ($(this).val()) { $('.mobile-btn-search').attr('type', 'submit'); } }); });
you getting following error :
uncaught error: type property can't changed
check console please.
you should use .prop() instead :
$('.mobile-btn-search').prop('type') hope helps.
Comments
Post a Comment