I simply want some tabbing functionality on a facebook application (business) tabs
I have some basic HTML and JS [fbjs], this doesn't seem to work I have no clue whats wrong.
<div id="foo">foo div</div>
<script><!--
function changeText(evt){
evt.target.style.display = "none";
}
var foo = document.getEleme开发者_如何转开发ntById('foo');
foo.addEventListener('click',changeText);
//--> </script>
What am i missing?
It works for me in Chrome. What browser are you using? Are you sure the page you are embedding this code in doens't contain another element with id "foo"?
Facebook actually alters the JavaScript and DOM environment in which your scripts run when you run them in Facebook. FBJS (Facebook JavaScript) sets up several wrappers around things like events and DOM elements. That means that things like DOM_Element.style.some_attribute
will not work. If you want to get or set the styles of an element, you're going to need to use DOM_Element.getStyle()
and DOM_Element.setStyle()
instead.
Events work like the W3C specifies:
From the docs:
//add event listener to 'foo' div (mouseover & mouseout)
document.getElementById('foo').addEventListener('mouseover',myEventHandler);
document.getElementById('foo').addEventListener('mouseout',myEventHandler);
精彩评论