Tuesday, January 17, 2012

window.document.getElementById not working in the SharePoint 2010

recently i came across a problem with getElementById. I used this function in the master page in side a JavaScript but it returned  an error. I don't know why it happened and still finding the cause. however i used a alternative  method to archive this task.

var item = window.document.getElementsByName("tagName")[0];

This worked for me.


Wilmann Gomez said...

I'm trying to do the same in an HTML form webpart. can you clarify what the '[0]' does?

I would try to use it in the following way



Melick Rajee said...

@Wilmann Gomez,


[0] getting the first element of the array. because getElementByName("txtName") returns array not a single element