Celebrating 7 Years! Get up to $30 off GeneratePress Premium!

[Resolved] Adding JS to Page

Home Forums Support [Resolved] Adding JS to Page

Home Forums Support Adding JS to Page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #540186
    Mike

    Hello,

    My website https://gladstonevillagehall.org includes four lightweight grid columns with backgrounds and hyperlinked text within them. I am trying to allow the user to be able to click anywhere within the background and be taken to the link that the text contains. So far I have found the following JS able to do this,

    <script>
    $("div.lgc-column:nth-child(1)").click(function() {
      window.location = $(this).find("a").attr("href"); 
      return false;
    });
    </script>
    
    <script>
    $("div.lgc-column:nth-child(2)").click(function() {
      window.location = $(this).find("a").attr("href"); 
      return false;
    });
    </script>
    
    <script>
    $("div.lgc-column:nth-child(3)").click(function() {
      window.location = $(this).find("a").attr("href"); 
      return false;
    });
    </script>
    
    <script>
    $("div.lgc-column:nth-child(4)").click(function() {
      window.location = $(this).find("a").attr("href"); 
      return false;
    });
    </script>

    I am however struggling to impliment it. I have previously had it working, however after removing my smooth scrolling JS it is now refusing to work!

    Do you have any suggestions on how I could either better go about achiving what I wish or do you know of a way to insert the JS code? I have tried various snippit plugins, nothing seems to be working.

    Thanks,
    Mike

    GeneratePress 2.0.2
    GP Premium 1.6.2
    #540512
    Tom
    Lead Developer
    Lead Developer

    I would personally give each column a class (the same class), then do this:

    <script>
    jQuery( document ).ready( function($) {
        $(".your-custom-class").click(function() {
            window.location = $(this).find("a").attr("href"); 
            return false;
        });
    } );
    </script>
    #541219
    Mike

    Hello Tom,

    Thanks for that code, it works a treat! I added the same class to all of the columns and used your code, far more efficiant than four diffrent scripts!

    On another note, have you any ideas on how I can tune my https://gladstonevillagehall.org website to get better performance? I was able to get the loading times really down on my company site https://hosker.tech by compressing images etc, however after trying all those steps for https://gladstonevillagehall.org it seems still very slow to load. Any ideas?

    Thanks,
    Mike

    #541523
    Tom
    Lead Developer
    Lead Developer

    Pingdom is great for that. Check the file requests section here: https://tools.pingdom.com/#!/c38k3I/https://gladstonevillagehall.org/

    It will tell you which files are taking the most time to load.

    #542335
    Mike

    Hello,

    I suspect it may be the add this social widgets! Have to say, I am surprised at how much overhead they have, especially considering they are supposed to be developed professionaly.

    Think I will try removing the add this plugin and see what performance diffrence it gives.

    Thanks,
    Mike

    #542621
    Tom
    Lead Developer
    Lead Developer

    Those kinds of plugins can be brutal when it comes to performance.

    Glad I could help 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.