• Resolved Xanza

    (@xanza)


    I need some help getting a specific jQuery plugin to work with my wordpress installation.

    From header.php:

    <?php wp_enqueue_script('jquery'); ?>
    <script type="text/javascript" src="https://raw.github.com/ThrivingKings/Apprise/master/apprise-1.5.full.js"></script>
    <link rel="stylesheet" href="https://raw.github.com/ThrivingKings/Apprise/master/apprise.css" type="text/css" />
    <script>
    $(document).ready(function() {
    	apprise('Server Stats', {'verify':true,'animate':true}, function(r) {
    
    	}
    }
    </script>
    	<?php wp_head(); ?>
    </head>

    As you can see, I’ve included jQuery, the script’s CSS theme, and it’s jQuery/PHP library.

    I’m all setup and ready to use it, however I need to add a single onclick function to the link I want to use it on.

    <a href="#" onclick="apprise('This is the jQuery Alert!');">Link Name</a>

    I need to add that onclick attribute to this menu item:

    https://i.imgur.com/kcemZ.png

    However I can’t find the darn thing!?

    I’d appreciate any help that you guys can provide! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your onclick function should look like this

    $(document).ready(function() {
     jQuery('a').click(function(){
    
      //Your function goes here
    
     });
    });

    The selector ‘a’ in the example is very generic as we can’t actually see which elements you’re using.

    May you link us your website or Pastebin.com your HTML and CSS code?

    Thread Starter Xanza

    (@xanza)

    It may not be valid, but it seems to be working. Even without:

    jQuery('a').click(function(){
    });

    Here’s a working example: https://wonderproject.net/xanza.php

    As you can see, it just spawns a stylized alert. I’ve experimented with:

    <?php
    		wp_nav_menu(array(
    			'before'          => '',
    			'after'           => '',
    			'link_before'     => '',
    			'link_after'      => '',
    		));
    		?>

    However, they don’t do what I need. ??

    I need to effectively turn this:

    [ Moderator note: please don’t use blockquote for code. ]

    <li id="menu-item-238" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-238"><a>Server Information: <font color='gold'>Beta</font></a>

    Into this:

    <li id="menu-item-238" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-238"><a onclick="apprise('Test');">Server Information: <font color='gold'>Beta</font></a>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I don’t understand, those two blockquotes are the same.

    Thread Starter Xanza

    (@xanza)

    Sorry, fixed.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If this is still the problem

    I need to add that onclick attribute to this menu item

    I just recommend you use the jQuery I provided in the example above, as this allows you to select certain elements.

    Here’s an example
    https://stackoverflow.com/questions/3389792/adding-onclick-attribute-to-a-tag-using-jquery

    Thread Starter Xanza

    (@xanza)

    Oh jeeze! I didn’t even see it! haha. Thanks alot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘jQuery OnClick for Hyperlink’ is closed to new replies.