0

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...

1 Answer 1

2

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");
        }
    });

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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