SaidbakR
SaidbakR

Reputation: 13544

Select all links in a DIV except of an ID

I have a div with an id. This div contain several links except one with a specified id. I have the following selector:

$("#smiley-box a").click(...

Now I need the same selector but it must be NOT applied to the link of the id moreSmilies

I tried this faulty code, which causes halting execution of the original code:

$("#smiley-box a :not(#moreSmilies)").click(function(e){
        //smiley = $(this).attr('href').substr(1);
        //$("#message").insertAtCursor(" "+smiley+" ")
        e.preventDefault();     
      })
    });

An example of the HTML I have:

<div id="smiley-box">
  <a href="#">someImage</a>
  <a href="#">someImage</a>
  <a href="#">someImage</a>

     <a id="moreSmilies" href="#">Another Task</a>
</div>  

Upvotes: 0

Views: 243

Answers (2)

dezman
dezman

Reputation: 19358

Remove the space after a because you are targeting that element with the not selector.

$("#smiley-box a :not(#moreSmilies)")

should be

$("#smiley-box a:not(#moreSmilies)")

Upvotes: 2

gregmatys
gregmatys

Reputation: 2198

$("#smiley-box a:not(#moreSmilies)")

remove space gap after a

Upvotes: 2

Related Questions