Thank you for checking my question.
I am trying to display the following array as an unordered list on the page:
var answers = ["cat", "dog", "horse", "hamster", "duck"]
However, if within this array there is this variable:
var x = $('#my-input').val()
I would want it to be removed from the displayed array. That is, if a user types in, for example, "duck" into the input, I don't want the "duck" to be among the array items displayed on the page. I hope I'm being clear.
Here is the js code I use to display the array onto the page:
$("#button").click(function(e){
var answers = ["cat", "dog", "horse", "hamster", "duck"]
var x = $('#my-input').val()
if(jQuery.inArray(x, answers) !== -1) {
$('#my-div').append(answers);
}
});
As you can see I am struggling with two things:
1) appending the array as an unordered list of elements (I am looking for a better solution than manually typing in: $('#my-div').append("<ul> + <li> + answers[0] + </li> + </ul>")
for all items.
2) removing one item from the array which is the value of the input.
Thanks again!