当前位置: 动力学知识库 > 问答 > 编程问答 >

css selectors - jQuery click but not the first-child

问题描述:

I have a list

HTML

<ul class="choices">

<li><a href="#" data-flag="en"><img class="flag" src="/img/flag/United Kingdom.png" alt="" /></a></li>

<li><a href="#" data-flag="de"><img class="flag" src="/img/flag/Germany.png" alt="" /></a></li>

<li><a href="#" data-flag="es"><img class="flag" src="/img/flag/Spain.png" alt="" /></a></li>

<li><a href="#" data-flag="fr"><img class="flag" src="/img/flag/France.png" alt="" /></a></li>

<li><a href="#" data-flag="it"><img class="flag" src="/img/flag/Italy.png" alt="" /></a></li>

</ul>

I'm trying to code in jQuery the ability to only allow an action on everything BUT the first child

I tried the following but to no avail

jQuery

$('.choices li:not(:first-child) a').click(function(e){

e.preventDefault();

console.log("clicked");

});

Could someone maybe help me out with my code?

网友答案:

There is nothing wrong with code you can check in the given demo link. Make sure you have code in $(document).ready(function(){ //your code...});

Live Demo

$('.choices li:not(:first-child) a').click(function(e){
    e.preventDefault();
    //console.log("clicked");
    alert("clicked");
});​
分享给朋友:
您可能感兴趣的文章:
随机阅读: