I've been getting help with this script seen below. It allows one input box to be used to put values into a text area and also display a list of the items. The items can be deleted once inserted:
// If JS enabled, disable main input
$("#responsibilities").prop('disabled', true);
// $("#responsibilities").addClass("hidden");
// If JS enabled then add fields
$("#resp").append('<input placeholder="Add responsibility" id="resp_input" ></input><input type="button" value="Add" id="add"> ');
// Add items to input field
var eachline='';
$("#add").click(function(){
var lines = $('#resp_input').val().split('\n');
var lines2 = $('#responsibilities').val().split('\n');
if(lines2.length>10)return false;
for(var i = 0;i < lines.length;i++){
if(lines[i]!='' && i+lines2.length<11){
eachline += lines[i] + '\n';
}
}
$('#responsibilities').text($("<div>" + eachline + "</div>").text()).before("<li>"+$("<p>"+lines+"</p>").text()+"<span class='right'><a href='#'>Remove</a></span></li>");
$('#resp_input').val('');
});
$(document).on('click', '.right a', function(){
var el = $(this).closest('li')
var index = $('li').index(el);
var text = eachline.split('\n');
text.splice(index, 1);
eachline = text.join('\n')
$('#responsibilities').text(eachline)
el.remove()
})
I was wondering if it would be possible to tag links in the list with the following information:
<span refid="1">Remove</span>
By tagging the links in this way I was thinking I could easily point to them with jquery if I wanted to delete it or later edit it.
Is there room to simplify this script in this way?