Remove Specific Characters from String Jquery

jQuery removing '-' character from string

$mylabel.text( $mylabel.text().replace('-', '') );

Since text() gets the value, and text( "someValue" ) sets the value, you just place one inside the other.

Would be the equivalent of doing:

var newValue = $mylabel.text().replace('-', '');
$mylabel.text( newValue );

EDIT:

I hope I understood the question correctly. I'm assuming $mylabel is referencing a DOM element in a jQuery object, and the string is in the content of the element.

If the string is in some other variable not part of the DOM, then you would likely want to call the .replace() function against that variable before you insert it into the DOM.

Like this:

var someVariable = "-123456";
$mylabel.text( someVariable.replace('-', '') );

or a more verbose version:

var someVariable = "-123456";
someVariable = someVariable.replace('-', '');
$mylabel.text( someVariable );

jQuery - Remove certain characters from string

You are replacing the string, you need to apply the change back to the element. And if you have multiple elements, you need to loop over each one.

jQuery(".dataIssue").each( function () {
var elem = $(this);
var txt = elem.text().replace('T00:00:00.000','');
elm.text(txt);
});

Remove specific characters from string jquery

You can simply recreate the list on change of a box

let els = [...document.getElementsByClassName('check')];els.forEach(e => e.addEventListener('change', () => {  document.getElementById('foo').value = els.filter(x => x.checked).map(x => x.value).join();}))
.flex {  display: flex;  flex-direction: column;}
<div class="flex">  <input id="foo" />  <label><input type="checkbox" class="check" value="A"/>A</label>  <label><input type="checkbox" class="check" value="B"/>B</label>  <label><input type="checkbox" class="check" value="C"/>C</label></div>

How to remove the character form string using jQuery?

A simple String.replace with regex /[a-z]/ig can do!

var str = "avc234jw6";var no = parseInt(str.replace(/[a-z]/ig, ""));
console.log(no);

jQuery remove character from text

Change:

$(this).html()

to:

$(this).html().replace('%','')

jsFiddle example

Using javascript/jquery to remove text after a certain character

You can easily do it with .split() like this:

var text = 'daslkdaskldj.asdasdasd';
text.split('.')[0];

here is fiddle

How to remove special characters like $, @, % from string in jquery

You should explore Regex.

Try this:

var str = 'The student have 100% of attendance in @school';str=  str.replace(/[^\w\s]/gi, '')document.write(str);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

removing parts of a string that starts and end with a specific word/char Jquery

It looks like you're trying to remove attributes from an html string. Use jquery to do that instead.

var str = "<li class='classname1 classname2' value='some value' > a sample content </li ><li class='classname1' value='another value' >another sample content</li><li class='classname1' value=\"yet another value\" >another sample content</li ><li><ul><li class='classname1 classname2' value='some nested value' > a nested sample content </li ></ul></li><li>A value='not' in an element</li>";
//Create an element to hold our htmlvar el = $("<div></div>").html(str);//get all decendant elements and loop themel.find("*").each(function(){ //Remove the attribute $(this).removeAttr("value");});
str = $(el).html();console.log(str);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

How to remove specific character surrounding a string?

Search for character mask and return the rest without.

This proposal the use of the bitwise not ~ operator for checking.

~ is a bitwise not operator. It is perfect for use with indexOf(), because indexOf returns if found the index 0 ... n and if not -1:

value  ~value   boolean
-1 => 0 => false
0 => -1 => true
1 => -2 => true
2 => -3 => true
and so on