1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

what this means : var questionNumber = $(this).parents().eq(2).index(); ?

Discussion in 'jQuery' started by kamalmajid, Feb 6, 2014.

  1. #1
    Hi,
    I am new to jquery, can you please explain to me what this line means :
    var questionNumber = $(this).parents().eq(2).index(); ?
    Thanks
     
    kamalmajid, Feb 6, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Looks to be a complicated way of returning the index of the given matching element.
    The code assigns a variable (var) named questionNumber - this variable looks for the containing object's ($(this)) parents, finds number 3 (.eq(2) <- zero-based indexing) and returns that items index() - I'm a little unsure as to what this is supposed to do.
    Have a look here:
    https://api.jquery.com/eq/ regarding .eq()
    and here:
    http://api.jquery.com/index/
    regarding .index()
     
    PoPSiCLe, Feb 6, 2014 IP
  3. kamalmajid

    kamalmajid Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thanks lot,
     
    kamalmajid, Feb 7, 2014 IP