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 withindexOf()
, becauseindexOf
returns if found the index0 ... n
and if not-1
:value ~value boolean
-1 => 0 => false
0 => -1 => true
1 => -2 => true
2 => -3 => true
and so on
function trim(s, mask) { while (~mask.indexOf(s[0])) { s = s.slice(1); } while (~mask.indexOf(s[s.length - 1])) { s = s.slice(0, -1); } return s;}
console.log(trim('??? this is a ? test ?', '? '));console.log(trim('abc this is a ? test abc', 'cba '));
Related Topics
Get a List of Dates Between Two Dates Using JavaScript
Filereader Onload With Result and Parameter
Trying to Load a Script File from My Node Server - Get 404
Display Data Label (Legend) in Line-Chart Using Chartjs
How to Get a File() or Blob() from an Url in JavaScript
How to Set the Multi Sliders in One Page
The Onclick Is Not Working on First Click
Copy/Paste from Excel to a Web Page
How to Get Multiple Comma Separated Values from Url
React - Clearing an Input Value After Form Submit
Matching a Forward Slash With a Regex
How to Convert Postgresql Time Without Time Zone to Date in JavaScript
Trigger Click in Typescript - Property 'Click' Does Not Exist on Type 'Element'
Node Server Running But Localhost Refusing to Connect
How to Push Value Pair into Object Using Method
How to Avoid Scientific Notation for Large Numbers in JavaScript
Jquery Ajax Readystate 0 Responsetext Status 0 Statustext Error