You can extend jQuerys selectors like this (doesn't quite work yet,
sorry):

$.extend($.expr[':'],{
    jpg: function(a) {
        return $(a).filter('img').attr('href').split('.').pop().match(/
jp/i);
        // return $(a).is("img[href$='jpeg']"); also could work
    }
});

Will let you do this:
$(':jpg').hide();
Or:
if ($(this).is(':jpg')) {
// do stuff with this
}

Hopefully someone will be able to do this so it actually works!

Have a look at: 
http://docs.jquery.com/Selectors/attributeEndsWith#attributevalue
and: 
http://james.padolsey.com/javascript/extending-jquerys-selector-capabilities/

On Jan 6, 5:03 pm, the_woodsman <elwood.ca...@gmail.com> wrote:
> Hi all,
>
> I have a function that determines (a bit hackily!) if an image is a
> jpeg.
>
>         isJpeg=function(src)
>         {
>                 mySplit=src.split('.');
>                 extension=mySplit[mySplit.length-1];
>                 isJpg=(extension=='jpg' || extension=='jpeg' || 
> extension=='JPG' ||
> extension=='JPEG');
>
>                 return isJpg;
>         };
>
> I think I might be able to rewrite this as a JQ selector involving the
> image's src attributes, something like:
> $('img').filter("img[src*!='.jpg']")
>
> But I can't get this to work- and I'm especially unsure how to do the
> variations of the extension in an OR clause.
>
> Any tips?
>
> Thanks!

Reply via email to