Jquery : .replace part of string returns "Unexpected token ILLEGAL" -


i have googled, , browsed around really, weird known error while now, cannot figure out what's wrong code, , why gives me error "unexpected token illegal".

the line fails 1 :

var temp = existingtags.replace(tagtoremove, '');​ 

code :

ondelete: function (item) {     var existingtags = $('.lbltags').html();      var tagtoremove = item.name + ',';      var temp = existingtags.replace(tagtoremove, '');​      $('.lbltags').text(temp); } 

data :

existingtags = "oddity,strange,weird,ohyeah,"    tagtoremove = "weird," 

you have invisible ("zero-width space") character @ end of line, making line invalid. note if put cursor after semicolon , hit right left, cursor doesn't appear move @ all.

this can happen when copy code around, particularly websites.

you can delete offending character, or if copy , paste code below looks identical has been cleaned up, rid of error.

ondelete: function (item) {     var existingtags = $('.lbltags').html();     var tagtoremove = item.name + ',';     var temp = existingtags.replace(tagtoremove, ''); // zero-width space removed here     $('.lbltags').text(temp); } 

as per andreas's comment, jsfiddle display offending character in red if paste code, shown here.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -