0

I am very New to JavaScript. Now i am trying to make a Google Chrome Extension which a click a Button on a specific web address. But the Site opens only for 30 second.. So i just saw the button color is GREEN and the button text is- " Move To " so how can i trigger that button ? I am Trying for this. But its not Working.

var b = $('button[class*="Move To"]')[1]
       $(b).click();
Zig Mandel
  • 19,571
  • 5
  • 26
  • 36

2 Answers2

0

You can use :contains.

var b = $( "button:contains('Move To')" )[1]
b.trigger('click');

https://api.jquery.com/contains-selector/

Or if text is exactly Move To you can use this:

var b;
if($('button').text() == 'Target'){
    $('button').trigger('click');
}
0

fire click event on a button containing particular text

js

$("button:contains('Move To')").trigger( "click" ); 

HTML

<button id="btn">Move To</button>
Ruhul
  • 990
  • 7
  • 15
  • So it will trigger that button which contains text "Move To ".. Right ? – Arif Rubayet Aug 24 '16 at 11:43
  • Ideally, yes. Rather simply try this $("button:contains('Move To')").trigger( "click" ); – Ruhul Aug 24 '16 at 11:47
  • Thanks. I will .. :) – Arif Rubayet Aug 24 '16 at 11:50
  • @ArifRubayet : Please mark it as answered, if it solves your problem. – Ruhul Aug 24 '16 at 11:58
  • . one more question If i want to trigger A link text.. Like going www.google.com then at the top you can see ( Gmail ) how to click that on ? its not button type. So what is it ? Sorry i am trying to mark your ans Up.. but system saying My reputation is Below 15. what to do !!! – Arif Rubayet Aug 24 '16 at 12:03
  • It can be achieved in a similar way, see http://stackoverflow.com/questions/5811122/how-to-trigger-a-click-on-a-link-using-jquery – Ruhul Aug 24 '16 at 12:06