最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if container contains specific element - Stack Overflow

programmeradmin0浏览0评论

I have container, that i got using $(this).parent(). And i want to check if this container contains element with tag form. Is there any way to do this with jquery?

I have container, that i got using $(this).parent(). And i want to check if this container contains element with tag form. Is there any way to do this with jquery?

Share Improve this question asked Feb 26, 2013 at 14:26 sanny Sinsanny Sin 1,5553 gold badges18 silver badges27 bronze badges 2
  • Please post a plete code example. – j08691 Commented Feb 26, 2013 at 14:27
  • use: $(this).parent().find('form').length – Boynux Commented Feb 26, 2013 at 14:27
Add a ment  | 

3 Answers 3

Reset to default 7
var container = $(this).parent();
var hasForm = container.find('form').length > 0;

Try this

if ($(this).parent().find('form').length)
   alert('its here')

You can use has function

if($this.parent().has('form').length > 0);
发布评论

评论列表(0)

  1. 暂无评论