1

I am trying to find a pure java script solution this; http://jsfiddle.net/IMAGINEUX/AQrNs/1/

I would like it to fire once the DOMready:

    $('#menu-item-156').mouseover(function(){
$(this).find('ul').slideDown();

});

$('#menu-item-156').trigger('mouseover');

Thanks,

Matt

imagineux
  • 89
  • 5

2 Answers2

0

Simply prefix your jQuery selector with your page class assigned to the body element by Wordpress, something like:

$('.my-page #menu-item-156').mouseover(function(){
     $(this).find('ul').slideDown();
});

$('#menu-item-156').trigger('mouseover');

This will make sure that the Javascript fires only on the desired page.

Sunyatasattva
  • 5,619
  • 3
  • 27
  • 37
0

You could either prepend it with the single page class as @Sunyatasattva mentioned or you could enqueue that script only on the page you need to use it on.

functions.php

function enqueue_scripts() {
    wp_register_script( 'dropdown', get_template_directory_uri() . '/lib/js/dropdown.js', array( 'jquery' ), 1.0, true );

    if ( is_page( 156 ) ) :
        wp_enqueue_script( 'dropdown' );
    endif;

}

add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
ferne97
  • 1,063
  • 1
  • 10
  • 20
  • I have a plugin that allows me to insert – imagineux Apr 19 '13 at 19:20
  • Have you tried wrapping it in `jQuery(document).ready(function($) { });` Is there a reason why you are not able to use jQuery? – ferne97 Apr 19 '13 at 20:04
  • I think I may have confused the crux of the issue This is the functionality I need: but I have no Idea how this would look in – imagineux Apr 19 '13 at 21:33
  • It would look like this.. http://jsfiddle.net/ferne97/AQrNs/3/. Looks like you have a few html syntax errors going on as well. The menu-item-156 id is missing an opening quote and looks like there is an extra tag at the end. – ferne97 Apr 20 '13 at 01:40