Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - replace text in Val()

Tags:

jquery

replace

I'm trying to replace parts of a Val() in jquery with some text but am not sure how to do this. $(this).val() returns "# number of...." - I would like to replace # with custom text, but Val doesn't seem to have a replace() function. I'm quite new to JQuery, so I might be missing something obvious. Thanks for any help

like image 781
o-logn Avatar asked Mar 06 '10 03:03

o-logn


1 Answers

You can pass a function to .val() in 1.4+ like this:

$("#mySelector").val(function(i, v) { //index, current value
  return v.replace("#","Custom Text");
});
like image 59
Nick Craver Avatar answered Oct 13 '22 06:10

Nick Craver