Site logo

[Resolved] JS in Hook do not give me id back

Home Forums Support [Resolved] JS in Hook do not give me id back

Home Forums Support JS in Hook do not give me id back

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2459297
    Peter

    Hi,
    i use a hook to put some JS on it – this works realy fine. But now i will make a litte function this didn’t work. I am not sure if i make somethink wrong with the hook now.

    Hook:

    <script>
    jQuery(document ).ready(function ($) {
        $('.link').on('click', function (e) {
            e.preventDefault();
            var id = $(e.target).attr('id');     
            $('.tabref').hide();
            $('#' +  id  + '-tabdetail').show();
    			
        }); 
    });	
    </script>

    What will i do:

    when i click the href with id=”one” then the div with id=”one-tabdetail” will show all other div with class “tabref” close.
    The hide function work but i didn’t get the id from the href.
    an example is here: https://jsfiddle.net/G8jK2/1/

    My settings at the hook: wp_footer – show only at the page what i need.
    Is this my fault how to make the js in generatepress or a js failure?

    #2459369
    David
    Staff
    Customer Support

    Hi there,

    GeneratePress or its Hook don’t interfere with how Javascript works. So if its not working then its an issue with the Javascript.
    First place to check is in the Browser Developer Tools > Console tab ( Right Click > Inspect the page to open in browser ). See if there are any errors showing before or after you click.

    Or share a link to the page on your site where i can see this and i can take a look.

    #2459434
    Peter

    Hi there,

    thanks for the fast Answer – i solve the Errors. At the Moment the “hide” action work. But not the Show ID.

    I Deleteted The Live Link because was test – i edit it when it is live.

    Between the “JS BLOCK” is this feature – the Content is “dynamic”. Thanks a lot for Help

    #2459498
    David
    Staff
    Customer Support

    I think your issue is because there are multiple elements using the same ID.
    I found this method which uses Classes for the target element.

    https://stackoverflow.com/a/5018087

    Maybe that is better solution ?

    #2459559
    Peter

    Your support is awesome!
    I read a lot and found a lot of solutions – also now my first time that i need help – you make it!

    Great Template – Great Team – Great Support!!!

    Solution: if you want to hide/show all divs simultaneously than you have to give all divs | if you want to hide/show one div at a time than you can do this with id

    #2460113
    David
    Staff
    Customer Support

    Glad to be of help 🙂

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