Skip to main content

How to add "Not Found" text into empty div or by specific class in jquery?

Add Not Found text into empty div or by specific class in jquery


<!DOCTYPE html>

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

var not_found_dt = "<div class='not_found_dt'>Not Found</div>";

var demo_str = $('#demo').text();

demo_str = demo_str.replace(/\s/g, '');

if(demo_str.length == 0){

$('#demo').html(not_found_dt);

}

});

</script>

</script>

</head>

<body>


<div id="demo"></div>


</body>

</html>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...