I am trying to create a set of buttons that behave like a list, where an array is created from the values selected.
Below is the function for checking if the value already exists in the array, and if it does not it will not add the new value.
function linearSearch(arrayName, sValue)
{
Array.prototype.exists = function(search){
for (var i=0; i<this.length; i++)
if (this[i] == search) return true;
arrayName.push(sValue);
return false;
}
}
Here is the jquery click function (of the listed items) where this function is called:
con_array = [];
$('.con_button').live('click', function (e) {
e.stopPropagation()
$(this).html('<div class="fun_button_center"></div>');
con_value = $(this).attr('data-value');
linearSearch(con_array, con_value);
alert(con_array);
});
The function works perfectly fine if it is inside of the click function without parameters. Yet in this circumstance, where it would be optimal because I can reuse it, no value is displayed with alert(con_array);