-2

How to change Text1 and Text2 to AnotherText1, AnotherText2 with help jQuery?

<div class="col-md-8">

  <div class="btn-group pull-right">
     <button type="submit" class="btn btn-primary">Text1</button>
  </div>                                                                    

  <div class="btn-group pull-left">
     <button type="reset" class="btn btn-warning">Text2</button>
  </div>
</div>
Vivek Singh
  • 2,453
  • 1
  • 14
  • 27

3 Answers3

1

//if you want to change the text only then use 
$("button[type='submit']").text('anything1');
$("button[type='reset']").text('anything2');

//if you want to change the text on click a event then use 
$("button[type='submit']").click(function(e) {
  $(this).text('on click anything1');
});

$("button[type='reset']").click(function(e) {
  $(this).text('on click anything2');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<div class="col-md-8">

  <div class="btn-group pull-right">
     <button id="btn1" type="submit" class="btn btn-primary">Text1</button>
  </div>                                                                    

  <div class="btn-group pull-left">
     <button type="reset" class="btn btn-warning">Text2</button>
  </div>
</div>
Mayank Rai
  • 49
  • 8
0

Please check this

<div class="col-md-8">

  <div id="btn1" class="btn-group pull-right">
     <button type="submit" class="btn btn-primary">Text1</button>
  </div>                                                                    

</div>
<script>$('#btn1').text("AnotherText1");</script>
Mahesh
  • 371
  • 3
  • 11
0

You can achieve this with .html('AnotherText')

Example:

<button type="reset" id="btn1" class="btn btn-warning">Text1</button>

<script> $("#btn1").html('AnotherText1') </script>

Maks
  • 1
  • 2