jQuery closest(); not working

家住魔仙堡 提交于 2019-11-28 08:24:45

.closest() finds the nearest parent element, .validation-error is not a parent of the name-input element. You need the .validation-error element which comes under the same tr as the input element

You need

$(this).closest('tr').find('.validation-error').show();

or

$(this).closest('td').next().find('.validation-error').show();

Try my version Demo Fiddle although Arun P. Johny's answer is much better..

$(this).parent().siblings().find('.validation-error').show();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!