简体   繁体   中英

How do I get javascript to affect “.gallery a” but not “.gallery a h3”?

I'm using Lightbox like so:

$('#gallery a').lightBox();

The html looks like this:

<div id="gallery">
<div class='holder'>
    <div class='thumb'> 
        <a href='images/all-tomorrows-parties.jpg'>
        <img src='images/thumbs/all-tomorrows-parties-t.jpg' width='140' height='120' /></a>
    </div>  
    <div class='title'>
        <h3>
            <a href="http://www.amazon.com/">
                All Tomorrow's Parties<br />
                William Gibson
            </a>
        </h3>
    </div>
</div>

So the javascript affects every link () inside of a .gallery div. I want it to only affect the thumb class, not the title class. How can I do that?

I'm pretty new at Javascript :/

只需将该类添加到您的选择器:

$('#gallery .thumb a').lightBox();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM