Jquery How to make insertBefore only work once, on first click?

JQuery

$(function(){
 $('#4').click(function() {
 $('<input name="if4" type="text" value="other price>"').insertBefore('form textarea');
   });
 });

      

Html

    <form>
< input name="name" type="text" value="Enter your name" /><br />
< input name="contacts" type="text" value="Contact info" /><br />
< select name="services">
< option value="1">1</option>
< option value="2">2</option>
< option value="3">3</option>
< option id="4" value="Other">4</option>
< /select><br />
< textarea name="description">Description</textarea><br />
< /form>

      

And another question about this, when I click on option number 4 twice, 2 new fields appear, is there a way to fix it that the new field only appears 1 time, after the first click?

+2


a source to share


1 answer


$(function(){
 $('#4').one('click', function() {
  $('<input name="if4" type="text" value="other price>"').insertBefore('form textarea');
 });
});

      



+3


a source







All Articles