jquery appending issue with multiple element conditional function
<p>I am mapping a object, and appending the elements from the object, while i map the elements i am checking the object value and appending the elements appropriately. in my function all are correct i believe, but the last 'if' condition only appending the element, rest of the condition not appending any thing... what would be the fix for this?</p>

<pre><code>var processModules = function (mData) {
    $.map(mData, function (val,i) {
        $(val.container).append(
            $(val.type === 'content' || val.type === 'navigation' ?
            $('&lt;div /&gt;',{
                'class':val.attributes['class'],
                id:val.attributes.id})
            .append(val.title ? $('&lt;h2 /&gt;',{text:val.title}) : "")
            .append(val.subtitle ? $('&lt;h3&gt;',{text:val.subtitle}) : "")
            :
            val.type === 'form' ? $('&lt;form /&gt;',{
                id:val.attributes.id,
                'class':val.attributes['class'],
                action:val.action,
                name:val.name
            })
            .append($('&lt;legend /&gt;',{text:val.title}))
            .append(
                $.map(val.fields, function (val,i) {
                    var element;
                    if (val.label) {
                        element = $('&lt;label /&gt;',{text:val.label}); // it is not appending
                    }
                    if (val.type) {
                        element = $('&lt;input /&gt;',{id:val.id}) // only this is appending, if i place anything after this, only the last condition appends.. any what is the issue? pls check my json tree in the jsfiddle.
                    }
                    return element;
                } )
            )
            : ""));
    } )
}
</code></pre>

<p><a href="http://jsfiddle.net/EFFNr/" rel="nofollow">jsfiddle here for json</a></p>

<p>thanks in advance.</p>
