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.

I encountered a strange problem with my JavaScript (jQuery) when trying to modify the behavior of my Media Uploader in Wordpress 3.5

Image filter selector

This was my JQuery:

$('.attachment-filters').change(function(){
    if($(this).val() === 'uploaded'){
        alert("Uploaded images selected");
    } else {
        alert("Other option selected");
    }
});

And this was the part of the media uploader i wanted to react to:

<select class="attachment-filters">
    <option value="all" selected="selected">All media items</option>
    <option value="uploaded">Uploaded to this page</option>
    <option value="image">Images</option>
    <option value="audio">Audio</option>
    <option value="video">Video</option>
</select>

To my big frustration this worked perfectly in a JS fidle, however it failed miserably in my wordpress admin screen...

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The solution was to simply wrap my JQuery in a function like this:

$('#wpcontent').ajaxStop(function() {

    $('.attachment-filters').change(function(){
        if($(this).val() === 'uploaded'){
            alert("Uploaded images selected");
        } else {
            alert("Other option selected");
        }
    });

});
share|improve this answer
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.