using setElement with views in backbone

Following this tutorial went okay but I decided to give it another run with backbone 0.9 and the new setElement command. <script type=”text/javascript” id = “test” > SearchView = Backbone.View.extend({ initialize: function(){ this.render(); }, render: function(){ var template = _.template( $(“#search_template”).html(), {} ); //Right here this.setElement( template ); }, events: { “click input[type=button]”: “doSearch” }, […]

Difference in JSON objects using Javascript/JQuery

I have two JSON objects in Javascript, identical except for the numerical values. It looks like this: var data = { “eth0”:{“Tx”:”4136675″,”Rx”:”13232319″}, “eth1”:{“Tx”:”4″,”Rx”:”0″}, “lo”:{“Tx”:”471290″,”Rx”:”471290″} } var old = { “eth0”:{“Tx”:”4136575″,”Rx”:”13232219″}, “eth1”:{“Tx”:”4″,”Rx”:”0″}, “lo”:{“Tx”:”471290″,”Rx”:”471290″} } One object called “data” has the current values, another object called “old” has the same values from 1 second ago. I’d like […]

Clear element.classList

element.classList is of DOMTokenList type. Is there a method to clear this list?

How to validate with Javascript an Input text with Hours and Minutes

I have to build an HTML Form with an Input text field for Hours and Minutes. Something like: Name : [Foo] Surname : [Bar] Task : [Spam] Hours Minutes : [00:15] <– Input text. How can I help/validate/force user to compile Hours and Minutes values in the only allowed HH:mm format using Javascript? * Valid […]

Get subdomain and load it to url with greasemonkey

I am having the URL http://somesubdomain.domain.com (subdomains may vary, domain is always the same). Need to take subdomain and reload the page with something like domain.com/some/path/here/somesubdomain using greasemonkey (or open a new window with URL domain.com/some/path/here/somesubdomain, whatever).

Setting the POST-body to a JSON object with jQuery

I’m trying to write a JSON-based web API in a Sinatra app. I want to POST a JSON object as the post body (with the proper content-type set) but I’m struggling. In Cocoa, I’d do something like [mutableHTTPRequest setHTTPBody:dataRepresentationOfJSONObject]; And the content type, set to JSON, would then post the HTTP body as a JSON […]

How come the answer to every javascript question ends up being “jQuery”

I’ve been following the javascript questions here for the last few weeks, and I’ve found a common recurring theme. Almost any question asked on here that involves JavaScript gets answered with: “jQuery can do that” “there’s a plugin for that” “jQuery can make your bed for you.” Even questions referencing other libraries are answered by […]

Best way for simple game-loop in Javascript?

Is there a simple way to make a game loop in JavaScript? something like… onTimerTick() { // update game state }

AngularJS dynamic form field validation

I am trying to validate some form fields which are given to me from a backend endpoint… So basically the input elements are dynamically created inside a ng-repeat. Therefore, the input attributes are also dynamically added, such as the type, name, etc… However because the name attribute is dynamically added, when I try to validate […]

Click on a div to toggle a checkbox inside of it using javascript

This seems to be a simple problem, but I dont use alot of javascript. I have a div, with a checkbox in it, and would like the whole div to toggle the checkbox. This is what I have so far: <div style=”padding: 2em; border: 1px solid” onClick=”if (document.getElementById(‘cb’).checked) document.getElementById(‘cb’).checked=false; else document.getElementById(‘cb’).checked=true;”> <input name=”cb” id=”cb” type=”checkbox”> […]