Replace characters in a field on page load

Viewed 89

I need to remove the unwanted characters from a field. my current results inside the field are <DT></DT><DD>57 MINUTES</DD>

i try this but is not working

jQuery('display').val(function(index, val){
    return val.replace('<DT></DT><DD>', '').trim();
});
<input type="hidden" id="display" value="<DT></DT><DD>0 MINUTES</DD>">

the wanted result its only the minutes.

2 Answers
$($('#display').val()).text()

$($('#display').val()) This will convert your value into html.

.text() will retrieve the minutes field.

Try like this, use regular expression

and one small issue, you have missed selector #

$('#display').val($('#display').val().replace(/(<([^>]+)>)/ig,""))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="display" value="<DT></DT><DD>0 MINUTES</DD>">

Related