indexing - jquery get instance of parents class -


i'm dynamically adding links page each link launches modal.

i need find instance of link launched modal display right info.

so have

<div class='linkholder'><a href='#' data-toggle='modal' data-target='#mymodal'  class='modallink'>view</a>" 

i'm trying find link on page getting occurance of class linkholder.

with this:

   function testindex() {     var test = ($(this).parent('.linkholder').index());     alert(test); } 

clicking link launches alert -1 / not found

thanks

as adding these links dynamically, attach click event using on in document load such:

$(document).on('click', 'a.modallink', function(e) {     e.preventdefault();     alert($(this).parent('.linkholder').index()); }); 

example

the problem function have not passed this doesn't know $(this) is

edit

as per comment, if looking index linkholder can in div try this:

$('.linkholder').index($(this).parent('.linkholder')); 

example


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -