As per your explanation I think you are using asp.net buttons in the master page. So the ID of the control will automatically changed by the asp.net(Use developer tool to see the ID.)
So better to use the class name to select the element or use
ClientIDMode[
^](asp.net Control(set the value to Static)).