klewis
klewis

Reputation: 8360

get group of same elements

Is there an easy way to click on three button links to set an action, and leave the top link (one) alone, without adding additional classes to this HTML markup?

<div id="mlinks">
  <a href="one">one</a>
  <a href="two">two</a>
  <a href="three">three</a>
  <a href="four">four</a>
</div>


//SET THIS ON CLICK EVENT TO COMMUNICATE WITH THE BOTTOM 3 LINKS, AND LEAVE THE FIRST ONE ALONE.
$('#mlink a').on('click', function() {

})

Upvotes: 0

Views: 68

Answers (4)

jfriend00
jfriend00

Reputation: 707706

You can use .first() or .eq(0) to remove the first link item:

var links = $('#mlink a');
links.not(links.first()).on('click', function() {
    // code here
});

Upvotes: 1

wirey00
wirey00

Reputation: 33661

use .not() and :first to filter it out

$('#mlink a').not(':first').on('click',function(){ .. });

or :not() selector and :first

$('#mlink a:not(:first)').on('click',function(){ .. });

or :gt() selector - select all greater than index 0

$('#mlink a:gt(0)').on('click',function(){ .. });

Upvotes: 5

Gloria
Gloria

Reputation: 1053

$('#mlinks a:first').nextAll().on('click', function() { });

check link: http://jsfiddle.net/7zDpY/

Upvotes: 0

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Try using slice and take out one,

$('#mlink a').slice(1).on('click', function() {

});

DEMO: http://jsfiddle.net/RGCKu/

Upvotes: 1

Related Questions