开发者

FBJS JavaScript getElementById returning null?

开发者 https://www.devze.com 2023-02-16 07:21 出处:网络
FBJS is driving my mental, I am having problems with selecting elements. I have the following on the content of my page:

FBJS is driving my mental, I am having problems with selecting elements. I have the following on the content of my page:

 <button id="sendmessage" type="submit" style="border: 0; background: transparent">
        <img src="Button.png" alt="Submit" />
        <div id="output">Send Message</div><span id="overlay"></span>
  </button>

And as part of my FBJS I have

var refSendMessage = document.getElementByI开发者_JAVA百科d('sendmessage');
var refOutput = document.getElementById('output');

However

refSendMessage.setDisabled(true);

Gets the error Uncaught TypeError: Cannot call method 'setDisabled' of null

But

refOutput.setTextValue("Sending...");

Works fine!

Why is the type of refSendMessage null but refOutput is fine? The ID's are declared in the same place?

Need a JS wizard please :-)

Many thanks for your time,


Extra information, if I use <span id="sendmessage"></span>, no error occurs. Could this be a Facebook Bug?


  1. Make sure you don't have anything else with id 'sendmessage' on the page.
  2. Try to change <button> to an <input type="button"> with id 'sendmessage' and see if document.getElementById('sendmessage') still returns null. If not, perhaps Facebook has trouble with the <button> element?
  3. Try looking at the rendered markup and make sure the Facebook-generated id specified inside document.getElementById() matches the Facebook-generated id of your button element. If they don't match, then of course a null will be returned.
0

精彩评论

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