jquery - How to create html tags each with their ID via a button with JavaScript? -
i have button in html click executes javascript function creates new field id in hidden div.
i wanted each new field (tag) has created "id" specifies, not id code (below). need different record in database entered in each.
can me ?
$(document).ready(function () { $('#addpergunta').click(function () { var x = 1; var div = $('#perg-box'); var divtext = $('<div />'); var text = $('<select />'); text.attr('class', 'form-control').attr('id', 'id-pergunta' + x); divtext.append(text); div.append(divtext); $('#div_perg').show(); }); });
here:
$(document).ready(function () { var count = 1 $('#addpergunta').click(function () { var div = $('#perg-box'); var divtext = $('<div />'); var text = $('<select />'); text.attr('class', 'form-control').attr('id', 'id-pergunta' + count); divtext.append(text); div.append(divtext); count++; $('#div_perg').show(); }); });
Comments
Post a Comment