tags:

views:

44

answers:

1

I would like to make sure if a textbox has any content at all, that jQuery can show it's parent (an <li class="hidden_dedication">) element and set add a class of 'shown'. I'm pretty sure that it should be something like this, but cannot get it to work:

    if ($('li.hidden_dedication input').val() !== null) {
         $(this).parent().show().addClass('shown');
    }

I cannot figure it out.. any ideas?

Many thanks

+1  A: 

Compare against the empty string '' instead of null.

Jimmy Cuadra
Hi Jimmy, thanks for your response, I actually used this rather than macek's solution in the end.Do you know how I would addClass to only the li's that have a value, not the ones that don't?
Zander
If you change `null` to `''`, your code looks fine, but that's assuming that `this` is actually referring to what you say it is. Without seeing more context I can't say for sure.
Jimmy Cuadra