Remove Part of String Variable with jQuery

By March 9, 2018 No Comments

Quick and easy explanation of the jQuery command replace.

The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match.

Here’s an example of the syntax and how it works.

//Set the jQuery Variable var ipAddress = ''; //Set text in document $('.initialVar').text(ipAddress); //We want to remove the "/10" from the ipAddress variable var ipAddressReplace = ipAddress.replace('/10',''); //Set text in document $('.afterVar').text(ipAddressReplace);

You can view a demo of this here.

Leave a Reply