我无法让我的if / else语句起作用

时间:2016-05-14 03:04:08

标签: javascript

我正在写一个声明,说如果#process-description中有任何内容显示#process-work,则隐藏它。

HTML

 <div id="process-work">
        <h2 id="process-title">Process Work</h2>
        <p id="process-description"></p>
    </div>

JS

            'zeckoshop' : {
            'title' : 'zeckoShop',
            'description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'link' : 'http://darrenbachan.com/playground/zeckoshop/index.html',
            'images': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ],
            'tags': [
                'Web Design',
                'Web Development'
            ],
            'process-description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'process-wireframes': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ]
        }


if('#process-work') {
            $('#process-description').html(projectData['process-description']).show();
        } else {
            $('#process-work').hide();
        }

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找代码中的这一变化:

if($('#process-description').length) {
            $('#process-description').html(projectData['process-description']).show();
        } else {
            $('#process-work').hide();
        }