DEV Community

Jenique Knoesen
Jenique Knoesen

Posted on

I need help

Hey everyone, I am stuck on this task, even my team lead does not know how to do this.

So I need to hide a section when the field within that section are all hidden, this what I have so far:

var salary = {value: $('.tdannualsalary').show() };
var salarym = { value: $('.tdsalary12monthspreceding').show() };
var salaryincome = { value: $('.tdannualincome').show() };

if (salary.value === $('.tdannualsalary').show() && salarym.value === $('.tdsalary12monthspreceding').show() && salaryincome.value === $('.tdannualincome').show()) {
    $('.tdsalaryearned').show();
}
else {
    $('.tdsalaryearned').hide();
}
Enter fullscreen mode Exit fullscreen mode

but this hides the section permanently and that's not what I want

Top comments (1)

Collapse
 
moopet profile image
Ben Sinclair

It's difficult to follow what you're trying to do, but assuming this is jQuery, the .show() method doesn't return anything useful. It's an action, so when you try to compare it or assign it to something, that's not going to do what you seem to think it is.

What do you think salary.value === $('.tdannualsalary').show() does? It's doing an exact comparison between a value you previously set, and that comparison should be true, but it doesn't mean anything for your logic.

I think you're trying to check whether something is visible, which you could do with .is(':visible') if I remember correctly. Use that for comparisons and use .show() or .hide() when you want to perform the action.