placing the numbers with string values

Viewed 43

I have the following function which adds dymaic fields upon button click

It is working fine,

all i want is to replace the number which is count with the data attribute value because data attribute has the icon and the name

function addNewField() {
    count = totalFields() + 1;
    field = $("#dynamic-field-1").clone();
    field.attr("id", "dynamic-field-" + count);
    field.children("label").text("Handler " + count); // it shows as Handler1, Handler2 
    field.find("input").val("");
    $(className + ":last").after($(field));

    followers = $("#dynamic-followers-1").clone();
    followers.attr("id", "dynamic-followers-" + count);
    followers.children("label").text("Number of Followers ");
    followers.find("input").val("");
    $(className + ":last").after($(followers));
  }

I want this to be Handler (Twitter + Icon) // twitter and icon are part of the data attribute because the values come from database

HTML

<div id="dynamic-field-1" class="form-group col-md-6 dynamic-field" data-name="twitter" data-icon='<i class="fab fa-twitter"></i>'>
  <label for="field" class="font-weight-bold">Handler</label>
  <input type="text" id="field" class="form-control" name="field[]" />
</div>
<div id="dynamic-followers-1" class="form-group col-md-6 dynamic-field">
  <label for="field" class="font-weight-bold">Number of Followers</label>
  <input type="text" id="fieldfollowers" class="form-control" name="fieldfollowers[]" />
</div>
0 Answers
Related