• Resolved slandoulsi

    (@slandoulsi)


    Hi,

    I have been using jQuery selector extensivly in my project but the THIS selector is causing me problems. The answer must be straightforward but… not for me !

    I have a button inside a personnel class fieldset. This fieldset is duplicated 20 times with the same button in each one. The button calls the resetpersonnel() function here below. I would like the indexpersonneltobedeleted variable to give the index of the personnel fieldset that has been clicked.

    It seems that I’m not using the THIS selector the right way.

    I appreciate if you can help me with this.

    
    function resetpersonnel()
    {
    var indexpersonneltobedeleted = jQuery('.personnel').index(jQuery(this).closest('.personnel'));
    
    ...
    }

    Best Regards,
    Skander

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The correct would be passing the button as parameter, for example if the resetpersonnel is called from the onclick event of the button, you should call it as: resetpersonnel(this);

    and then, modify the function as:

    function resetpersonnel( e )
    {
    var indexpersonneltobedeleted = jQuery('.personnel').index(jQuery(e).closest('.personnel'));
    
    ...
    }

    and that’s all.
    Best regards.

    Thread Starter slandoulsi

    (@slandoulsi)

    perfect! thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using THIS jQuery selector in a onclickevent function’ is closed to new replies.