user3731917
user3731917

Reputation: 41

Alternative of onclick for html5

 <div id="btnSideToggle" onclick="Viewer.toggleThumbnails();"><img src="assets/pgThumbs.png"></div>

Due to CSP restriction on Firefox OS Marketplace i cant use onclick on html5 page, can anyone please tell me alternative of onclick for HTML5

here is the full code : http://jsfiddle.net/edd4225/v65qZ/

Upvotes: 3

Views: 19825

Answers (1)

maček
maček

Reputation: 77786

This will work for you

var button = document.querySelector("#btnSideToggle");

button.addEventListener("click", function onclick(event) {
  Viewer.toggleThumbnails();
  event.preventDefault();
});

You could simplify it with Function.prototype.bind (requires ECMAScript >= 5)

button.addEventListener("click", Viewer.toggleThumbnails.bind(Viewer));

Note that an Event will still be sent as the first argument to the toggleThumbnails handler.

Upvotes: 4

Related Questions