Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

in a sidebar I have:

<div id="my_id"> [shortcode]</div>

It outputs a title that when hovered on drops down to show a menu.

When hovering on the title a background color shows up and disappears when the mouse moves down to the menu items.

I need for the background color to remain as long as the menu has focus, I need something like:

If #my_id has focus then .my_link {background:red;}

I have looked and the only thing that looked promising was (not really sure how to use this)

JQuery:js_focus

$(document).ready(function() {    

   $('input').blur(function(){
            $('input').removeClass("focus");
      })
         .focus(function() {                
             $(this).addClass("focus")
      });

});

CSS:

.focus {
    background:red;
    }

In functions.php:

function load_scripts() {
   wp_enqueue_script('jquery');
   wp_enqueue_script('my_javascript_file', 'http://example.com/wp-content/themes/Child-Theme/js_focus.js', array('jquery'));
}    
add_action('init', 'load_scripts');

Then in style.css:

.focus .my_link {background:red;}

Is this a good approach?, if so (not working at the moment) I only want focus on the menu to give the background color.

If not a good approach any other ideas all are welcomed and appreciated

Thanks Tim

share|improve this question
    
Did you wp_register_script first? codex.wordpress.org/Function_Reference/wp_register_script, and don't use the init hook, use wp_enqueue_scripts or admin_enqueue_scripts hooks. –  soulseekah Mar 30 '12 at 19:12
add comment

1 Answer 1

up vote 1 down vote accepted

Your jQuery is not correct (syntax and logic), this isn't really a WordPress question. To toggle focus effects you can do something like this, http://stackoverflow.com/questions/5608181/jquery-toggle-focus

share|improve this answer
    
Thanks both for your imput –  Tim Mar 31 '12 at 12:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.