Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
JQuery - How can I NOT select an img with a certain class?
Old 04-27-2009, 11:01 AM JQuery - How can I NOT select an img with a certain class?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
I have a jQuery script that works a little too well.
It wraps all the images on the page with a link to a larger image version which in turn is viewable via the jQuery LightBox script.

Unfortunately not every image on the page is a thumbnail.
Some of course are navigation elements.

The obvious answer is to just add a class like "thumb" to the relevant
images and target them that way HOWEVER I am building the site for
somebody who I am sure knows (and cares) nothing about classes or IDs.
All they know is how to upload images and maybe add an ALT attribute.

So to tackle it a different way I will set up a jQuery script that takes a shotgun approach BUT I want to put a class of "ignore" into the non-thumbnail images.

Hope that makes sense.

Here is the code if that helps.
Code:
<script type="text/javascript">

    $(function() {
        //wraps each image with a link to the larger version
        $("#category img").each(function() {
            var Img = $(this).attr('src');
            var imgExt = /(\.\w{3,4}$)/;
            var newImg = new Image();
            newImg.src = Img.replace(imgExt,'_big$1');
            var a = $('<a/>').attr('href', newImg.src);
            $(a).addClass("lightboxer");
            $(this).wrap(a);
        });//ends "each" function
        
        //binds the links to the lightbox function
        $('a.lightboxer').lightBox();
            
    }); //ends "ready" function
    
    
</script>
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-27-2009, 12:59 PM Re: JQuery - How can I NOT select an img with a certain class?
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
I'm quite a beginner at JQuery, but i'd imagine what you'd want to do is give the images that you don't want to display, some sort of function that returns "false".
__________________
"If you say something interesting, people will remember your name" ~ Anonymous


Please login or register to view this content. Registration is FREE
.asp <- Irony
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
Old 04-27-2009, 01:29 PM Re: JQuery - How can I NOT select an img with a certain class?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
very simple:
Code:
$("#category img:not(.ignore)").each(function() {

});
note the :not pseudoselector (CSS3)
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 04-27-2009 at 01:31 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-28-2009, 01:14 AM Re: JQuery - How can I NOT select an img with a certain class?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Thanks a lot!

Dont you just love jQuery for its beautiful simplicity.

Actually though, I think I have an even better approach.
I realized that all the thumbnail images are coming from a special directory called "products" which is just for product images.

So a better way would be to use jQuery to:

1. Look at all images on the page.
2. Examine their "src" attribute.
3. Select only those where the src includes the directory "/products/"
4. Wrap those img in the LightBox classed <a> tag.

So how can I achieve POINT 3 above??
TWD is offline
Reply With Quote
View Public Profile
 
Old 04-28-2009, 08:10 AM Re: JQuery - How can I NOT select an img with a certain class?
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Solved my own question.

Code:
$("img[src*='products/']").each(function() {

//same code goes here//

});//ends "each" function
TWD is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to JQuery - How can I NOT select an img with a certain class?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15277 seconds with 12 queries