Clicking the price with class "onward" should take the data "I want this data "
<span class="onward">4518</span>
<table>
<tr>
<td class="select_fly">
<form>
I want this data
</form>
</td>
</tr>
</table>
$(document).on('click', '.onward', function(){
var owner = $(this).closest('td').siblings('td.select_fly').html();
console.log(owner);
});
But for me owner is coming as "undefined" can anyone help me how to get data " I want this data"
Try the code.
$(document).on('click', '.onward', function(){
var owner = $(this).next('table').find('td.select_fly').html();
console.log(owner);
});
You can use
var owner = $(this).next('table').find('td.select_fly').html();
So your JS will be :
$(document).on('click', '.onward', function(){ var owner = $(this).next('table').find('td.select_fly').html(); alert(owner); });
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script> <span class="onward">4518</span> <table> <tr> <td class="select_fly"> <form> I want this data </form> </td> </tr> </table>
If you want to have only the text, then
var owner = $(this).next('table').find('td.select_fly form').html();
This will give only
I want this data
You need to modify your javascript to:
$(document).on('click', '.onward', function(){
var owner = $(this).next('table').find('form').html();
console.log(owner);
});
Please find a JSBin for the issue here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.