• Resolved danniee001

    (@danniee001)


    Hello!

    I wanted to make a whole table row clickable and used this javascript to achieve this:

    <script type=”text/javascript”>
    jQuery(document).ready(function($){
    $(‘.tablepress-id-16’).on( ‘click’, ‘tr’, function() {
    var $a = $(this).find(‘a’).last();
    if ( $a.length )
    window.location = $a.attr(‘href’);
    } );
    });
    </script>

    I have two questions however.

    1. WordPress warns me and says: expected { found window instead on this row window.location = $a.attr(‘href’);. Is this something I should fix?

    2. I put this javascript on every page where I display a table. Is there any more effecient way to do this, like link to an external page with the javascript or maybe it doesnt make any difference?

    Thank’s in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    1. Yes, for clearer syntax, you should change those two lines to

    if ( $a.length ) {
      window.location = $a.attr(‘href’);
    }

    2. This JS code only affects table 16, so that you should only put it on pages with that table 16 (unless you use it in a modifed version for the other tables as well).
    Given that this JS code is so short, I don’t think that it makes sense to move it to a separate file.

    Regards,
    Tobias

    Thread Starter danniee001

    (@danniee001)

    Much appreciate Tobias, thank you ??

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The use of Javascript correct?’ is closed to new replies.