I have an onclick event that passes a $(this) argument to a function.
<tr class="myTr">
<td>
Han Solo
</td>
</tr>
<script>
$('body').on('click','.myTr',function(){
doSomething($(this));
});
</script>
Now, I want to add another step. I want to show a button, and after this button is click, doSomething() is supposed to be called.
<tr class="myTr">
<td>
Han Solo
</td>
</tr>
<button id="myBtn" style="display:none">Submit</button>
<script>
$('body').on('click','.myTr',function(){
$('#myBtn').show();
});
$('#myBtn').click(function(){
doSomething(???);
});
</script>
How do I pass the $(this) to the second click event?
I could easily store the $(this)as a tag of the button, something like this:
$('body').on('click','.myTr',function(){
$('#myBtn').attr('origin', $(this));
$('#myBtn').show();
});
$('#myBtn').click(function(){
var tr = $(this)attr('origin');
doSomething(tr);
});
But I was wondering if there is a more elegant way to solve this?
$('#myBtn').data('origin', $(this));and$(this).data('origin');