Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #471397

    when using this function for example

    function add_custom_div(){
    ?>
    <script>
    jQuery(“.bt-01”).click(function(){
    window.location = jQuery(this).find(“a:first”).attr(“href”);
    return false;
    });
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_div’);
    ?>

    >>>is it possible to add more classes separated with a comma within the same function code? Rather than repeating the function code for every class I need to effect.
    So for example,

    function add_custom_div(){
    ?>
    <script>
    jQuery(“.bt-01, .bt-02, .bt.03, .bt-04”).click(function(){
    window.location = jQuery(this).find(“a:first”).attr(“href”);
    return false;
    });
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_div’);
    ?>

    #471476

    Hey user877!

    That’s not a theme question but yes you can add commas like that. You can learn more about jQuery here, https://api.jquery.com/category/selectors/.

    Cheers!
    Elliott

    #471675

    thanks appreciate it.

    #471981

    Hey!

    Glad we could help :)

    Cheers!
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘calling multiple classes (optimising code)’ is closed to new replies.