开发者

find id of element [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reope开发者_如何学运维ned, visit the help center. Closed 10 years ago.

Is there any way of determining the id attribute of any html element.


It's simple as pie:

var id = anyElement.id

The reverse function (determine element by id):

var anyElement = document.getElementById(id);


I suggest you edit your question to represent accurately what you are looking for.

Based on your comments, if you are looking for the FIRST DIV, use something like this:-

x=document.getElementsByTagName("div"); 
if (x!= 'undefined' && x.length > 0 ) 
   document.write(x[0].id);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜