javascript - jQuery get button classname on button click -


i trying assign textbox value on button click. assigning value previous textbox of button. used var classic = window.event.target.class;
alert(classic); gives error undefined.

how can identify button clicked either class name or id or other way.

jquery(document).ready(function() {         var formfield;      var classic = window.event.target.class;      /* user clicks button on custom field, runs below code opens new window */      jquery(classic).click(function() {          formfield = jquery(this).prev('input'); //the input field hold uploaded file url          tb_show('','media-upload.php?tb_iframe=true');             return false;         });      //adding custom function thick box close function tb_close() .      window.old_tb_remove = window.tb_remove;      window.tb_remove = function() {          window.old_tb_remove(); // calls tb_remove() of thickbox plugin          formfield=null;      };         // user inserts file post. run custom if user started process using above process      // window.send_to_editor(html) how wp handle received data         window.original_send_to_editor = window.send_to_editor;      window.send_to_editor = function(html){          if (formfield) {              fileurl = jquery('img',html).attr('src');              jquery(formfield).val(fileurl);              tb_remove();          } else {              window.original_send_to_editor(html);          }      };     });
<form method="post" action="options.php">      <?php settings_fields( 'option-man-settings-group' ); ?>      <?php do_settings_sections( 'option-man-settings-group' ); ?>      <div class="frame">      <table class="form-table">           <tr valign="top">          <th  class="label">logo url:</th>          <td><input type="text" name="logo-setting" size="45" value="<?php echo esc_attr( get_option('logo-setting') ); ?>" /></td>          <td><input name="op"  class="option-man button" type="button" value="upload image" /></td>          </tr>                      <tr valign="top">          <th scope="row" class="label">header:</th>          <td><input type="text" name="main-header" size="45" value="<?php echo esc_attr( get_option('main-header') ); ?>" /></td>          </tr>            <tr valign="top">          <th scope="row" class="label">carousel-url:</th>          <td><input type="text" name="carousel-image" size="45" value="<?php echo esc_attr( get_option('carousel-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>                    <tr valign="top">          <th scope="row" class="label">message:</th>          <td><input type="text" name="message-short" size="45" value="<?php echo esc_attr( get_option('message-short') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">question header:</th>          <td><input type="text" name="question-cur" size="45" value="<?php echo esc_attr( get_option('question-cur') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">happy clients post image:</th>          <td><input type="text" name="happy-image" size="45" value="<?php echo esc_attr( get_option('happy-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">happy clients post header:</th>          <td><input type="text" name="happy-header" size="45" value="<?php echo esc_attr( get_option('happy-header') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">happy clients post text:</th>          <td><input type="text" name="happy-text" size="45" value="<?php echo esc_attr( get_option('happy-text') ); ?>" /></td>          </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">solution builder post image:</th>          <td><input type="text" name="builder-image" size="45" value="<?php echo esc_attr( get_option('builder-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">solution builder post header:</th>          <td><input type="text" name="builder-header" size="45" value="<?php echo esc_attr( get_option('builder-header') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">solution builder post text:</th>          <td><input type="text" name="builder-text" size="45" value="<?php echo esc_attr( get_option('builder-text') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">agile process post image:</th>          <td><input type="text" name="agile-image" size="45" value="<?php echo esc_attr( get_option('agile-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">agile process post header:</th>          <td><input type="text" name="agile-header" size="45" value="<?php echo esc_attr( get_option('agile-header') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">agile process post text:</th>          <td><input type="text" name="agile-text" size="45" value="<?php echo esc_attr( get_option('agile-text') ); ?>" /></td>          </tr>            <tr valign="top">          <th scope="row" class="label">honesty transparency post image:</th>          <td><input type="text" name="honesty-image" size="45" value="<?php echo esc_attr( get_option('honesty-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">honesty transparency post header:</th>          <td><input type="text" name="honesty-header" size="45" value="<?php echo esc_attr( get_option('honesty-header') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">honesty transparency post text:</th>          <td><input type="text" name="honesty-text" size="45" value="<?php echo esc_attr( get_option('honesty-text') ); ?>" /></td>          </tr>          <tr valign="top">          <th scope="row" class="label">medtegra image:</th>          <td><input type="text" name="client1-image" size="45" value="<?php echo esc_attr( get_option('client1-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">hdfc image:</th>          <td><input type="text" name="client2-image" size="45" value="<?php echo esc_attr( get_option('client2-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>            <tr valign="top">          <th scope="row" class="label">iitjobs image:</th>          <td><input type="text" name="client3-image" size="45" value="<?php echo esc_attr( get_option('client3-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">productiveteams.com:</th>          <td><input type="text" name="client4-image" size="45" value="<?php echo esc_attr( get_option('client4-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          <tr valign="top">          <th scope="row" class="label">jfys image:</th>          <td><input type="text" name="client5-image" size="45" value="<?php echo esc_attr( get_option('client5-image') ); ?>" /></td>          <td><input  class="option-man button" type="button" value="upload image" /></td>              </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">clients message:</th>          <td><input type="text" name="client-message" size="45" value="<?php echo esc_attr( get_option('client-message') ); ?>" /></td>          </tr>          </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">google+:</th>          <td><input type="text" name="google" size="45" value="<?php echo esc_attr( get_option('google') ); ?>" /></td>          </tr>          </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">twitter:</th>          <td><input type="text" name="twitter" size="45" value="<?php echo esc_attr( get_option('twitter') ); ?>" /></td>          </tr>          </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">facebook:</th>          <td><input type="text" name="facebook" size="45" value="<?php echo esc_attr( get_option('facebook') ); ?>" /></td>          </tr>          </tr>          </tr>          <tr valign="top">          <th scope="row" class="label">linkedin:</th>          <td><input type="text" name="linkedin" size="45" value="<?php echo esc_attr( get_option('linkedin') ); ?>" /></td>          </tr>                </table>      </div>      <?php submit_button(); ?>    </form>

i believe want.

$('.form-table').on('click', 'button, input[type="button"]', function () {      // previous input     var input = $(this).closest('td').prev('td').find('input');      // button class     alert($(this).attr('class'));      // button id     alert($(this).attr('id'));       // code here     tb_show('', 'media-upload.php?tb_iframe=true');      return false;  }); 

demo: https://jsfiddle.net/tusharj/o59eoomx/2/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -