开发者

What exactly does this javascript getElementsByTagName syntax do?

I have this:

var targetTitle = targetElement.getElementsByTagName('title').item(0);

Am i passing a plain string into targetTitle? or what am i passing exactly?

Which element would be item(1), item(2), etc... in here:

<title>title1</title>
<title><title2</title>

Does it just look for ALL the title tags on the page and return the 0,1,2/?

Would this return 'title2':

targetElement.getElementsB开发者_Go百科yTagName(‘title’).item(1)


The targetTitle will contain a reference to the DOM element object for the title tag.

The code only gets the first title tag, as there is only one in each document.


You're getting the first <title> element from targetElement.

item(0): <title>title1</title>
item(1): <title><title2</title>

Note: those indexes starts with zero, not one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜