javascript - Referencing the anchor tag that was clicked: What am I doing wrong? -


i keep getting

"cannot read property 'split' of undefined"

, indicating me $(this) in below code undefined. why that?

html:

<tbody>    <tr>       <td><a class='edit-link' id='jobid-3'>motion designer</a></td>       <td>2015-07-21 11:06:57</td>    </tr>    <tr>       <td><a class='edit-link' id='jobid-2'>web developer</a></td>       <td>2015-07-21 09:53:36</td>    </tr>    <tr>       <td><a class='edit-link' id='jobid-1'>creative team manager</a></td>       <td>2015-07-21 09:41:20</td>    </tr> </tbody> 

js:

<script type="text/javascript">     jquery('.edit-link').click(function() {     {         var thisjobid = jquery(this).attr('id').split('-')[1];         console.log("thisjobid = " + thisjobid); // test     }); <script> 

there no event binding in code example.

so use this

jquery('.edit-link').on("click", function() {     var thisjobid = jquery(this).attr('id').split('-')[1];     console.log("thisjobid = " + thisjobid); // test }); 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -