jQuery to hide a HTML tag if the database value is NULL

I am using Dreamweaver's inbuilt PHP capabilities to build a small application. I am retrieving the data in a repeated ul, li structure which looks like this.

  • Client Name
  • Job Description
  • Year of Completion

Client Name and Job description will always have values and year of completion may have null values. If Year of Completion has null value the 'li' should not be displayed.

I am trying to do this with jQuery but looks complicated for me. Can I achieve this in PHP?


$array = array('client_name'=>'John', 'job_descr'=>'Programming', 'year'=>null);

foreach ($array as $data) {
    echo '<ul>';
    ($data['client_name']!=null)?echo '<li>'.$data['client_name'].'</li>':echo '';
    ($data['job_descr']!=null)?echo '<li>'.$data['job_descr'].'</li>':echo '';
    ($data['year']!=null)?echo '<li>'.$data['year'].'</li>':echo '';
    echo '<ul>';

If I understood correctly, this is what You need.

Doing it with PHP would be the logical way - you would have to show us the PHP source to help you on that - it would just involve an if statement checking for null and not echoing that list if it is true.. but to answer your jquery question.. if your output is this:

<ul id="this_is_the_list">
            <li>Client name value</li>
            <li>Job desc value</li>
            <li>This isnt null</li>
            <li>Another name value</li>
            <li>Another Job desc value - this one will be null</li>

your jquery would be:

$(document).ready(function() {
        //for each additional list within the target list
        //which has a 3rd li (i would suggest giving this a
        //class instead to better target it).
        $('#this_is_the_list li li:nth-child(3)').each(function() {
            if($(this).text().length < 1) { //if its empty
                 $(this).parents('#this_is_the_list > li').remove(); //remove its parent list item

Fiddle to demonstrate here: http://jsfiddle.net/QxcLS/

Need Your Help

jhipster session timeout configuration

spring security angularjs jhipster

I downloaded JHipster from git and tried to understand how to configure session timeout but couldn't find any web.xml or java-based class for that.