0

I have created my own plugin which has a custom script attached to it. I have added this in the correct manor like this:

add_action('admin_enqueue_scripts', 'add_search_script');
function add_search_script() {
    wp_register_script('search', plugins_url('search.js', __FILE__) );
    wp_enqueue_script('search');    
}

If i add an alert to the top of the .js file, and then refresh the plugin page the alert appears. Simple alert like this:

alert ('test');

However if i try and hide something with js, noting happens?

I target a class like this:

$(".simple").hide();

Which has no effect? I have also tried:

jQuery(".simple").hide();

Which again has no effect?

Any ideas on what could be the problem?

0

If your script is loading in the head of your admin page I would recommend wrapping your code in a document ready function

// wait till the entire dom is available before executing JS
// notice the $ this brings the $ into private scope if you wish to use it
jQuery(document).ready(function($){ 

    // put your page code here
    $(".simple").hide();

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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