Skip to content

Instantly share code, notes, and snippets.

@tapickell
Created April 18, 2013 15:42
Show Gist options
  • Save tapickell/5413754 to your computer and use it in GitHub Desktop.
Save tapickell/5413754 to your computer and use it in GitHub Desktop.
my button and label (for lack of a better term) in the html file and my corresponding js file
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.3.1.min.css" />
<script type="text/javascript" charset="utf-8" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.3.1.min.js"></script>
<title>Hello World</title>
</head>
<body>
<a href="#" data-role="button" data-inline="true" id="start_button" onclick="onStartButtonPress">Start Pom</a>
<div id="label"></div>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
function onStartButtonPress() {
var my_label = document.getElementById("label");
my_label.innerHTML = "<h1>onStartButtonPress called</h1>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment