Remove string using jQuery [duplicate]


Remove string using jQuery [duplicate]



This question already has an answer here:



-
=

done



if minus1str_1 enter "abcde" and minus1str_2 enter "abc" minus1_total = "de"


minus1str_1


minus1str_2


minus1_total



I want to know how to create code with jQuery.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





well this should be done with replace developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… and a listener on the button. What did you try so far?
– Lars-Olof Kreim
Jul 3 at 6:32






idownvotedbecau.se/unclearquestion
– bn4t
Jul 3 at 6:32




1 Answer
1



You can use replace() which will replace the string with '' so that it will simulate as if it has been subtracted:


replace()


''




$('#m_cal1').click(function(){
var minus1str_1 = $('#minus1str_1').val();
var minus1str_2 = $('#minus1str_2').val();
$('#minus1_total').html(minus1str_1.replace(minus1str_2,''));
});


https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js


-
=

done



If you want to subtract all the occurrences then use global replace like:




$('#m_cal1').click(function(){
var minus1str_1 = $('#minus1str_1').val();
var minus1str_2 = $('#minus1str_2').val();
$('#minus1_total').html(minus1str_1.replace(new RegExp(minus1str_2, 'g'),''));
});


https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js


-
=

done





thank you very much !!!!
– ctmong
Jul 3 at 6:43





@ctmong glad to help :)
– Ankit Agarwal
Jul 3 at 6:48





Can I ask you one more question?
– ctmong
Jul 3 at 7:15






@ctmong yes sure please. If its a bigger question you can create a new question
– Ankit Agarwal
Jul 3 at 7:22





I wanna know what to do if one more input is added to the code I asked ex) string - string - string / add: var minus1str_3 = $('#minus1str_3').val();
– ctmong
Jul 3 at 7:32



var minus1str_3 = $('#minus1str_3').val();

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?