Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

document.getElementsByTagName(...)[11] is undefined

  • 9 trả lời
  • 1 gặp vấn đề này
  • 11 lượt xem
  • Trả lời mới nhất được viết bởi inzmamulhaqansari25

more options

Hi team

i am trying to get the value of an element. var a=[]; a=document.getElementsByTagName("select")[11].options; a[0].text this code works fine in chrome's console but it does not work in firefox.

Infact, when i use document.getElementById("id").text it gives error as document.getElementById("id") is undefined. Please help me with this issue

Hi team i am trying to get the value of an element. var a=[]; a=document.getElementsByTagName("select")[11].options; a[0].text this code works fine in chrome's console but it does not work in firefox. Infact, when i use document.getElementById("id").text it gives error as document.getElementById("id") is undefined. Please help me with this issue
Đính kèm ảnh chụp màn hình

Tất cả các câu trả lời (9)

more options

Can you provide a working example of this issue on jsfiddle.net or codepen.io ?

more options

Do you have at least 12 <select> controls in the page?

What is the value of

document.getElementsByTagName("select").length
more options

@jscher2000, document.getElementsByTagName("select").length returns 43 in chrome however same code in firefox returns 2.

I do not understand why it is so

more options

@jscher2000, document.getElementsByTagName("select").length returns 43 in chrome however same code in firefox returns 2.

I do not understand why it is so

more options

That's a good question. Are you doing anything fancy with iframes or shadow DOM that could affect the scope of "document"?

more options

@jscher2000, yes, there is iframe and inside iframe, i have the content which i am trying to access

more options

I don't have a good sense of whether your script is running in the right document. Maybe a demo is the best next step:

TyDraniu said

Can you provide a working example of this issue on jsfiddle.net or codepen.io ?
more options

If you type/paste document.getElementsByTagName("select") in the Web Console and press Enter that you should see the DOM tree for these elements as an array that you can expand for inspection, so you can see if the correct element is found.

more options

Hi Team

i got it fixed other way..Thank you for your help