Skip to content Skip to sidebar Skip to footer

Detect Character In Div And Remove It Javascript Or Jquery

I have this div:

$340

I need to detect if inside of this div there is a dollar symbol, If so - remove it I'll explain again: I have got this code so far so I

Solution 1:

This is quite easy using a simple regex

var div = $('your selector here');
div.html(div.html().replace(/\$/g, ''));

Solution 2:

That's what I have meant, without the If condition:

$('h1').text( $('h1').text().replace("$", ''));  

Solution 3:

Something like this should work:

$("h1").each(function() {
  var $el = $(this);
  var text = $el.text().replace("$", "");
  $el.text(text);
});

Solution 4:

Try like this

var price = $("h1").html().replace(/[^\d\.]/g, '');
console.log(price);

Solution 5:

<!doctype html><htmllang="en"><head><metacharset="utf-8"><title>jQuery UI Dialog - Default functionality</title><linkrel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"><scriptsrc="//code.jquery.com/jquery-1.10.2.js"></script><scriptsrc="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script><script>
$( document ).ready(function() {  
    var val=$('#demo').html().replace('$','');
  $( "div" ).replaceWith( val );
});
</script></head><body><h1id='demo'>$540</h1></body></html>

Post a Comment for "Detect Character In Div And Remove It Javascript Or Jquery"