I have string
where 0,5,10 are ids, text are values and ## is delimiter.
I have id and i want to remove id's value
This is my following code, Please check and suggest.
code1
function remove_feature(id)
{
var feature_str = $("#features_post").val();
var feature_string = feature_str.replace(['id=feature_str'],'', 'gi');
window.jQuery("#features_post").val(feature_string);
window.jQuery("#"+id+"").remove();
alert(feature_string);
return true;
}
code2
function remove_feature(id)
{
var feature_str = $("#features_post").val();
var feature_string = feature_str.replace(id,'', 'gi');
window.jQuery("#features_post").val(feature_string);
window.jQuery("#"+id+"").remove();
alert(feature_string);
return true;
}
I have tried both of code but not working
Try this one with jquery : http://jsfiddle.net/h0qtxn7d/ Can also remove same multiple ids.
var k = "0=>zxz##5=>zxzx##5=>zxz##10=>zxz##1=>asdasd##12=>asdsad##10=>asdsad";
var obj = k.split("##");
var removeItem = 5;
alert('Array before removing the element = ' + obj)
obj = jQuery.grep(obj, function(value) {
return value.split('=>')[0] != removeItem;
});
alert('Array after removing the element = ' + obj);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments