) element and set add a class of \'shown\'. I\'m pretty sure tha" />
开发者

How do I detect a text input's value and set a class with jQuery?

开发者 https://www.devze.com 2022-12-27 11:39 出处:网络
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 tha

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


Compare against the empty string '' instead of null.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号