Javascript 如何操作JQuery以一个div为目标而不是另一个div

Javascript 如何操作JQuery以一个div为目标而不是另一个div,javascript,jquery,html,Javascript,Jquery,Html,如果这个问题有点简单,并且以前有过这样或那样的回答,我深表歉意,但我对JQuery还不熟悉,并且仍然在适应使用选择器,我不确定要搜索什么才能找到我需要的答案 我有两种不同的链接选择。其中一个我想应用JQuery,但不是页面的其余部分。我的第一个div选择器如下所示,这些是我希望应用JQuery的链接: <div id="tabs-1"> <a href='http://www.collectormania.com/'>Collectormania</a>

如果这个问题有点简单,并且以前有过这样或那样的回答,我深表歉意,但我对JQuery还不熟悉,并且仍然在适应使用选择器,我不确定要搜索什么才能找到我需要的答案

我有两种不同的链接选择。其中一个我想应用JQuery,但不是页面的其余部分。我的第一个div选择器如下所示,这些是我希望应用JQuery的链接:

<div id="tabs-1">
   <a href='http://www.collectormania.com/'>Collectormania</a>
   <a href='http://www.game.co.uk/'>Game</a>
   <a href='http://www.lipsum.com/'>Ipsum Generator</a>
   <a href='http://www.netflix.com'>Netflix</a>
   <a href='http://www.pixel2life.com/'>Pixel2Life</a>
   <a href='http://www.port-vale.co.uk/'>Port Vale</a>
   <a href='http://www.roleplayer.me/'>Roleplayer</a>
   <a href='http://stackoverflow.com/'>Stack Overflow</a>
   <a href='http://www.themarauders.co.uk/'>The Marauders</a>
   <a href='http://www.torrentz.com/'>Torrentz</a>
   <a href='http://www.trueachievements.com/'>True Achievements</a>
</div>

我不想将它们应用到的群体是:

<div id="social">
   <a href="#"><img src="images/social/deviantart.png" alt="DeviantArt"/></a>
   <a href="#"><img src="images/social/facebook.png" alt="Facebook"/></a>
   <a href="#"><img src="images/social/flickr.png" alt="Flickr"/></a>
   <a href="#"><img src="images/social/google+.png" alt="Google+"/></a>
   <a href="#"><img src="images/social/linkedin.png" alt="LinkedIn"/></a>
   <a href="#"><img src="images/social/tumblr.png" alt="Tumblr"/></a>
   <a href="#"><img src="images/social/twitter.png" alt="Twitter"/></a>
   <a href="#"><img src="images/social/youtube.png" alt="You Tube"/></a>
</div>

最后,要修改的JQuery是:

<script type="text/javascript">
    $("a[href^='http']").each(function() {
        $(this).css({
            background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
            "padding": "0px",
            "padding-bottom": "4px",
            "padding-left": "30px"
        });
    });
</script>

$(“a[href^='http']){
$(this.css)({
背景:“url(http://g.etfv.co/“+this.href+”)左中不重复“,
“填充”:“0px”,
“填充底部”:“4px”,
“左填充”:“30px”
});
});

如果要选择的所有链接都将位于该div中,则更快、更具体的选择器将是“#tabs-1A”,而不是“a[href^='http']”。因此,请尝试:

$("#tabs-1 a").each(function() {
    ...
});

将div ID放入选择器中:

$("#tabs-1>a[href^='http']").each(function() {
    $(this).css({
        background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
        "padding": "0px",
        "padding-bottom": "4px",
        "padding-left": "30px"
    });
});

你可以先检查一下身份证

<script type="text/javascript">
$('#tabs-1 > a[href^="http"]').each(function() {
    $(this).css({
        background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
        "padding": "0px",
        "padding-bottom": "4px",
        "padding-left": "30px"
    });
});
</script>

$('#tabs-1>a[href^=“http”])。每个(函数(){
$(this.css)({
背景:“url(http://g.etfv.co/“+this.href+”)左中不重复“,
“填充”:“0px”,
“填充底部”:“4px”,
“左填充”:“30px”
});
});


对于选择器:

那么问题是什么?我如何才能不将查询应用于社交div?