javascript - cloning HTML and render it with custom text -
i'm trying value of tb-team-name when clicking .tb-delete-team a reason renders
"are sure want delete
[object object]?"
when
$('.hutdb-modal-body').html(nameoutput);
it shows link should do. doing wrong? (i'm not @ jquery)
html
<tr role="row" class="odd"> <td width="80%;" class="row-label tb-team-name bold"><a href="/17/builder/12037">goon squad</a></td> <td class="tb-synergy">3</td> <td class="tb-team-overall">86.05</td> <td class="tb-delete-team"><a class="table-button" href="/s/builder/del/12037"><i class="fa fa-trash" aria-hidden="true"></i> delete</a></td> </tr> jquery
$('.tb-delete-team a').click(function(event) { event.preventdefault(); var addressvalue = $(this).attr('href'); var namevalue = $(this).parent('#my_teams_wrapper table tbody tr td').parent('#my_teams_wrapper table tbody tr').children('.tb-team-name').children('a'); var nameoutput = namevalue.clone().val('.tb-team-name'); $(this).each(function () { $('.hutdb-overlay').show(); $('.hutdb-modal').fadein(); $('.hutdb-modal-body').html('are sure want delete ' + nameoutput + '?'); $('.hutdb-modal-button-group').html( '<a class="cancel" href="#">cancel</a><a class="confirm" href="'+addressvalue+'"><i class="fa fa-trash" aria-hidden="true"></i> delete</a>' ); $('.hutdb-modal-button-group .cancel').click(function() { $('.hutdb-modal').hide(); $('.hutdb-overlay').hide(); }); }); });
try using below namevalue:
var namevalue = $(this).closest('tr').find('.tb-team-name').text(); closest matches , returns first parent selector in dom. see documentation
the above code first traverse in dom till meets first tr (its parent) , traverse down matched tr , finds .tb-team-name , retrieves value (or text of <a> tag).
you may not need nameoutput after that.
Comments
Post a Comment