I'm a student who is studying Python alone these days. Below is part of my HTML page's JavaScript code.
let temp_html_0 = `<div class="card">
<img class="card-img-top"
src="${image}"
alt="Card image cap">
<div class="card-body">
<a target="_blank" href="${url}" class="card-title">${title}</a>
<p class="reason-comment">REASON : ${comment}</p>
</div>
<div class="button-result">
<button type="button" class="btn btn-success" onclick="confirm()">Confirm</button>
<button type="button" class="btn btn-danger" onclick="reject()">Reject</button>
</div>
<br/>
</div>
`
javascript function :
function confirm(){
alert('confirmed????')
let test = $(this).parent().parent().find(".card-img-top").attr("src");
alert(test)
window.location.reload()
}
What I want to do is:
When user clicks btn-success button,
call confirm() function,
and get img src (${image}
in my code)
to call AJAX.
I tried code above but it didn't work. How can I get img src value?
$(this).parent().parent().find(".card-img-top").attr("src")
? I assume it's in theconfirm()
function but we probably need the code for it. Right now there is no minimal reproducible example which makes it hard to guess what's wrong . – VLAZthis
inside your function i.e :onclick="confirm(this)"
and then simply usefunction confirm(el) {let test = $(el).parent().parent().find(".card-img-top").attr("src")}
– Swati