adardesign
adardesign

Reputation: 35701

javascript [fbjs] in facebook pages/tabs

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.getElementById('foo');
foo.addEventListener('click',changeText);
//--> </script>

What am i missing?

Upvotes: 0

Views: 363

Answers (2)

Sean Vieira
Sean Vieira

Reputation: 159915

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);

Upvotes: 1

jd.
jd.

Reputation: 4098

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"?

Upvotes: 1

Related Questions