0

why "name" is not being replace here?

var foo = '<div>                <label class="required">_1_label__</label><div id="project_frontendbundle_car_1___name__"><div>                <label for="project_frontendbundle_car_carImages___name___position" class="required">Position</label><input type="number" id="project_frontendbundle_car_carImages___name___position" name="project_frontendbundle_car[carImages][__name__][position]" required="required" /></div><div>                <label for="project_frontendbundle_car_carImages___name___fileName">File name</label><input type="text" id="project_frontendbundle_car_carImages___name___fileName" name="project_frontendbundle_car[carImages][__name__][fileName]" maxlength="2000" /></div></div></div>';

var bar = foo.replace('_name_', '1');
$('body').text(bar);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
tirenweb
  • 30,963
  • 73
  • 183
  • 303

1 Answers1

4

Try

var bar = foo.replace(/_name_/g, '1');

g = Globally replace

iLikeBreakfast
  • 1,545
  • 23
  • 46