• Resolved gokh

    (@gokh)


    <script type="text/javascript">	
    	jQuery(document).ready(function ($) {
    			$('.tg-item').each(function () {
       $(this).find('a').removeAttr('href');  
    });
    });
    </script>

    Meteorite
    The .js code I added to header.php worked in the editor.

    Child theme
    But it did not work when added to the file “my-custom-functions.js and functions.php”. I wonder why? I added it to the .js code field inside the gallery plugin, it works.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Theme Author terrathemes

    (@terrathemes)

    Why would you add <script> tags to a .js file? Please take a look how you have to add jQuery in that file.
    You already have jQuery inside, just build that code like the one that is already there. The other code doesn’t have that too.

    Just use

    $('.tg-item').each(function() {
       $(this).find('a').removeAttr('href');  
    });

    Furthermore, adding that jQuery to the functions.php can’t work.

    Thread Starter gokh

    (@gokh)

    Without the <script> tag, I added the code to the file “my-custom-functions.js”, but it did not work.

    Theme Author terrathemes

    (@terrathemes)

    Please add a ; at the end of the first jQuery code.

    Alternatively you can try out this one

    jQuery(function($) {
      $('.tg-item-link').each(function() {
        $(this).removeAttr('href');  
      });
    });
    • This reply was modified 6 years, 6 months ago by terrathemes.
    Thread Starter gokh

    (@gokh)

    ; I added, I tried the alternative and it did not work.

    https://prntscr.com/jgknid

    Theme Author terrathemes

    (@terrathemes)

    I copied your code and on my development page it’s working fine. Would you please deactivate your caching plugin or clear its cache? You really have to clear the cache everytime you change the files.

    As long as you’re not finished with your page, you don’t really need the caching plugin activated. This only causes problems when developing.

    Thread Starter gokh

    (@gokh)

    Yes .. I have disabled W3 Total Cache and re-enabled it. Now it works.
    Is it better to keep the code in its own “css / js” panel? or is the “child theme” better?

    Theme Author terrathemes

    (@terrathemes)

    Is it better to keep the code in its own “css / js” panel?

    Which panel do you mean? Nonetheless I think it’s not important where it is, as long as it works.

    Thread Starter gokh

    (@gokh)

    “The Grid Gallery plugin” has its own css/js panel. The plugin is not affected by its own updates, right?

    Theme Author terrathemes

    (@terrathemes)

    Yes, they are not affected by updates.

    Thread Starter gokh

    (@gokh)

    Thanks..

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘.js code that does not work in child theme’ is closed to new replies.