Really struggling with this simple code here. I’m checking if the section with #setactionsuccess exists if not I want to create it and prepend it to the container. First part works smooth but it never goes to ‘else’ (and the condition is met – I triple checked that). Any help greatly appreciated.
if ($('#setactionsuccess')){
var currenttime = new Date();
$('#setactionsuccess').empty();
$('#setactionsuccess').html('<h2>Set successfully deleted</h2><p>Set was successfully removed from this Edition on '+currenttime+'</p>');
} else {
console.log('here');
var string = '<section class="successful" id="setactionsuccess"><h2>Set successfully deleted</h2><p>Set was successfully removed from this Edition on '+currenttime+'</p></section>';
console.log(string);
$('#currentsets').prepend(string);
}
if ($('#setactionsuccess'))always returns truebecause javascript cheks for
nullandundefinedand jquery never returns anullorundefined even when any element with id setactionsuccess dosent existstry looking for length for the selector
$('#setactionsuccess').length