0

how to Change dynamic button text on mouseover by jQuery,

button

 <button type="button" id="sendRequest" ><span>Avialable Now</span></button>

jquery

$(document).ready(function(){
    $('#sendRequest').hover(function() {
         $(this).find('span').text('Send Request');
    }, function() {
        $(this).find('span').text('Avialable Now');
 });
});

I want to change text on every dynamacly created button,with above I can change text on only single or first button.

Manjunarth
  • 313
  • 2
  • 7
  • 22
  • Give each of the dynamically created button a class name. And use that class name for changing the text – cdoshi Dec 21 '17 at 10:47

1 Answers1

4

Change your selector from $('#sendRequest') To $('button'). This will raise the event on the current button.

$(document).ready(function(){
    $('button').hover(function() {
         $(this).find('span').text('Send Request');
    }, function() {
        $(this).find('span').text('Avialable Now');
 });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="sendRequest1" ><span>Avialable Now</span></button>
<button type="button" id="sendRequest2" ><span>Avialable Now</span></button>
Mamun
  • 66,969
  • 9
  • 47
  • 59