I need to display a link in sweetalert html only if the var is not empty. Here is the code:
$('.patient-details').click(function(e) {
e.preventDefault();
var $this = $(this)
var name = $this.data('name');
var gender = $this.data('gender');
var age = $this.data('age');
var country = $this.data('country');
var address = $this.data('address');
var report = $this.data('report');
swal({
title: name,
html:
"Gender: " + gender +"<br>" +
"Age: " + age +"<br>" +
"Country: " + country +"<br>" +
"Address: " + address +"<br>" +
(report!=undefined?'<a href="' + report + '" target="_blank">View Report</a>':''),
});
});
I need the report link to be displayed only if var report is not empty. Here is the code pen: https://codepen.io/pamela123/pen/GOJZgo
I tried
if(report){
report = $this.data('report');
}
report is "undefined". report!=undefined is not working.
But how not to display the report link inside the html if report is empty ??
I know it is a simple javascript question, but being a newbie i could not get further.