jQuery如果Element有ID? [英] jQuery if Element has an ID?

查看:65
本文介绍了jQuery如果Element有ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择具有任何ID的元素?例如:

How would I select elements that have any ID? For example:

if ($(".parent a").hasId()) {
    /* then do something here */
}

我绝不是jQuery的高手。

I, by no means, am a master at jQuery.

推荐答案

喜欢这样:

var $aWithId = $('.parent a[id]');

根据OP的评论,测试如下:

Following OP's comment, test it like this:

if($aWithId.length) //or without using variable: if ($('.parent a[id]').length)

将返回具有指定属性ID的父类元素内的所有锚标记

Will return all anchor tags inside elements with class parent which have an attribute ID specified

这篇关于jQuery如果Element有ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆