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');     }    }); }); 

working fiddle.

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

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -