2016-07-07 30 views
5

Tôi có đoạn code sau đây để có được một phần tử bằng cách đó là thuộc tính:getElementsByAttribute() không phải là một chức năng

document.getElementsByAttribute("xlink:href",id); 

tôi nhận được lỗi:

Uncaught TypeError: document.getElementsByAttribute is not a function

Tôi không hiểu những gì đang xảy ra sai? Nó không phải là một chức năng tiêu chuẩn chrome?

+0

nên nó không được 'document.getElementsByAttribute ("id", id);' – Rab

Trả lời

6

Từ documentation:

Note that this method is only available on XUL elements; it is not part of the W3C DOM.

Sử dụng này:

document.querySelectorAll("[xlink|href='"+id+"']"); 
5

Is it not a chrome standard function?

Không, không phải vậy.

Từ MDN:

Note that this method is only available on XUL elements; it is not part of the W3C DOM.

Xem xét sử dụng querySelectorAll với an attribute selector để thay thế.

Các vấn đề liên quan