I am getting this error:
Uncaught Error: NOT_FOUND_ERR: DOM
Exception 8
Here is my code (please suggest anything to make it more efficient / cleaner):
Basically this is a button thats adding it’s ID to an array called ‘keywords’:
$('.add').live('click', function() {
if($(this).text() == "+Add") {
console.log("add triggered");
$(this).stop().animate({backgroundColor:'#999d92'}, 300);
$(this).html("-Rem").fadeIn('fast');
keywords.push($(this).attr("id"));
$("#response").append(keywords);
}
else {
$(this).stop().animate({backgroundColor:'#cc6633'}, 300);
$(this).html("+Add").fadeIn('fast');
var index = keywords.indexOf($(this).attr("id"));
keywords.splice(index, index+1);
$("#response").append(keywords);
}
});
What I want to happen is when “+ADD” is pushed the id attribute is added to the array, and when -REM is pushed then remove that id from the keywords.
Any advice would really be a help. When I just append $(this).attr(“id”) to the response div it does print correctly. I also tried surrounding it with a “String()” function (perhaps it was a reference to the resource and not the actual string?)
Thanks a head of time!
The second argument to
spliceis a number of items to remove, so that should probably be just1.But
keywordsis an array of strings? jQuery documents no such interface forappend.Do you want something like:?