javascript - Find and replace text in label jquery -
i've label ex. : <label id="labelid" class="control-label col-lg-4">some text ()</label>
, how can insert text in middle of brakets , after clear it?
i've tried :
$('#labelid').replace("()", "(new)");
but not work me
you've text using text()
replace using replace()
set replaced text label.
jquery solution :
var label_text = $('#labelid').text(); //get text $('#labelid').text( label_text.replace("()", "(new)") ); //replace , set text
pure js solution :
var label_text = document.getelementbyid('labelid').innertext; //get text document.getelementbyid('labelid').innertext = label_text.replace("()", "(new)"); //replace , set text
hope helps.
$(function(){ var label_text = $('#labelid').text(); $('#labelid').text( label_text.replace("()", "(new)") ); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label id="labelid" class="control-label col-lg-4">some text ()</label>
Comments
Post a Comment