I want all non-numeric characters to be removed from a div
for example:
<div class="publication_date> c2011. </div>
should appear
<div class="publication_date> 2011 </div>
I tried
$(".publication_date").html($(".publication_date").html().replace(/[^0-9]+/g, ''));
and it is giving all dates as 2000
You need to use
.each():The
.html()function, when passed no arguments, returns the value for the first element matched by the initial selector. If your first element had been “c2009.”, then all of your other elements would have been “2009” instead of “2000”.By using
.each(), you handle each “publication_date” element individually.Also I modified the regex a little;
\Dmeans “not a digit”.