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

Answers


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

Need Your Help

Does MVC pattern negate other design patterns?

oop design-patterns model-view-controller

So usually when working with the MVC you have a controller that controls the input a model that process it and makes it ready for the user and a view that display the "result" to the user.

Show element based on $scope variable value

angularjs ng-show

I am new to AngularJS and am trying to figure out how to show an HTML element based on a variable value.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.