javascript - Search for a comma and remove if orphan -


i have script acts filter remove elements page based on user types in, filtering works great, when user types keyword added list,

a users input this,

look, ma, these, are, keywords, boom

and , output of be,

  • look
  • ma
  • these
  • are
  • keywords

on clicking on 1 of list items remove list , user input, problem detecting whether keyword, need remove comma after word. there way can search see if need remove comma well, current script looks this,

$(document).on("click", ".remove-tag", function(e){         e.preventdefault();         $(this).parent().animate({             "width" : "0px",             "overflow" : "hidden"         }, 500, function(){             $(this).remove();             var str = $("#options_1").val();             console.log(str);             var newstr = str.replace($(this).text(), "");             console.log(newstr);             $("#options_1").val("");             $("#options_1").val(newstr);         });     }); 

with split , filtering, no regex:

var newstr = str.split(',').filter(function(n){return n.trim()}).join(','); 

fiddle


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -