How can I calculate time difference in JScript between two times in milliseconds or seconds?
For example, between 2010-04-23 15:03 and 2010-05-30 00:41
OKay first off this is really really similiar to the http://dribbble.com homepage.
In the simplest form possible. I have an image, and i'm trying to CSS it so that when i hover over the image, a DIV shows up with some text and a partially transparent background color.
I have no idea how to do this..
I am trying to learn backbone.js through the following example.
Then I got stuck at the point
ItemView = Backbone.View.extend
why you can use this.model.get?
I thought this is referring to the instance of ItemView that would be created. Then why would ItemView has a model property at all?!!
(function($){
var Item = Backbone.Model.extend({
defaults: {
part1: 'hello',
part2: 'world'
}
});
var List = Backbone.Collection.extend({
model: Item
});
var ItemView = Backbone.View.extend({
tagName: 'li',
initialize: function(){
_.bindAll(this, 'render');
},
render: function(){
$(this.el).html('<span>'+this.model.get('part1')+' '+this.model.get('part2')+'</span>');
return this;
}
});
var ListView = Backbone.View.extend({
el: $('body'),
events: {
'click button#add': 'addItem'
},
initialize: function(){
_.bindAll(this, 'render', 'addItem', 'appendItem');
this.collection = new List();
this.collection.bind('add', this.appendItem);
this.counter = 0;
this.render();
},
render: function(){
$(this.el).append("<button id='add'>Add list item</button>");
$(this.el).append("<ul></ul>");
_(this.collection.models).each(function(item){
appendItem(item);
}, this);
},
addItem: function(){
this.counter++;
var item = new Item();
item.set({
part2: item.get('part2') + this.counter
});
this.collection.add(item);
},
appendItem: function(item){
var itemView = new ItemView({
model: item
});
$('ul', this.el).append(itemView.render().el);
}
});
var listView = new ListView();
})(jQuery);
I'm trying to iterate through an array of elements. jQuery's documentation says:
jquery.Each() documentation
Returning non-false is the same as a continue statement in a for loop, it will skip immediately to the next iteration.
I've tried calling 'return non-false;' and 'non-false;' (sans return) neither of which skip to the next iteration. Instead, they break the loop. What am i missing?
Should not be such a hard question... I'm just having a hard time figuring out how to make operations on some jquery elements, particularly their indexes. Teh codez:
$( "#docSlider" ).css("background-image", "url(../../bundles/mypath/images/maquette/img" + $( "#selectable li" ).index( this ) + (".jpg)"));
I want to make the name of the picture I load depend on the index of a jQuery selectable. So I grab the index and try to add 1... but it can't work because "+" is also a concatenator.
I've tried to parseInt as well, but it was always worth 0.
How do I simply transform the index to an integer and then concatenate it with the rest of the string?
Thank you in advance!
Edit : I'm using a function that already exists, so I can hardly change the parameters (well, I guess I can't...)
I'm using JQuery and Prototype in this web application that I'm developing. I'm looking for a way to use Lightbox v2.04 by Lokesh Dhakar to play flash movies. If its not possible using the Lightbox v2.04 then what other ways can I accomplish the shadowing overlayed flash video pop-up with jquery and/or Prototype? The reason I'm set on v2.04 is because I'm using it already as an image gallery. I'm using flv type flash files if that helps.
So, here is the function for pre-filtering "CHILD":
function(match){
if ( match[1] === "nth" ) {
// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
// calculate the numbers (first)n+(last) including if they are negative
match[2] = (test[1] + (test[2] || 1)) - 0;
match[3] = test[3] - 0;
}
// TODO: Move to normal caching system
match[0] = done++;
return match;
}
The code is extracted from line 442-458 of sizzle.js.
So, why is the line var test = ..., have the exec inputing a boolean? Or is that really a string?
Can someone explain it by splitting it into a few more lines of code?
I am creating an ajax chat in rails and I am trying to get a div to scroll to the bottom without much luck.
I am wrapping everything in this div:
#scroll {
height:400px;
overflow:scroll;
}
Is there a way to keep it scrolled to the bottom by default using JS?
is there a way to keep it scrolled to the bottom after an ajax request?
I would like to keep the contents of large UI lists cached on the client, and updated according to criterial or regularly. Client side code can then just fill the dropdowns locally, avoiding long page download times.
How can I go about this? I mean, what patterns and strategies would be suitable for this?
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
<html xmlns="..." custom:xmlns="http://www.example.com/ns">
...
<div class="foo" custom:attr="bla"/>
...
</html>
How do I match each element that has a certain custom attribute using jQuery? Using
$("div[custom:attr]")
does not work. (Tried with Firefox only, so far.)
Backspace is the browser hotkey for Navigate Back To The Last Page. I know that when an input has the focus this hotkey is disabled. But I have keyup and keydown events binded to this input, and something I wrote is causing this trouble.
Do you know the solution?
I'd like to have a div expand to show contents when a user clicks their mouse in a text box to enter text. I haven't seen that around anywhere before. I know how to make things expand onClick, but can someone point me to what I'm looking for?
Basically, I have an email signup box that I just want to show the input field for the email address, but if the user actually decided to get on the email list, that div will expand to also ask them for their name and zipcode.
Thanks!
I've got jquery already set for the email form now, so I'd like to expand on that if possible:
Hi,
I have a swf file with a semi-transparent + tint effect and a HTMl element
<span id='mybutton'>My Button</span>
I want to place the swf over the span, so that i can see div/span/a the content through swf.
How can i achieve this?
i have following format of json in which i want to asscess 0.4 , kem , 2 , 2000 values
but it seems it doesn't have name index so how one can access it in jquery.
when i paste following code in json viewer then i am getting numerical index for 0.4 , kem , 2
"td": [
{
"@attributes": {
"class": "odd"
},
"span": [
"3",
"7"
]
},
"0.4",
"Kem",
"24\/04\/2010",
"2000",
"2",
"14000",
"Good",
"Buckley",
"56.0",
"2:05.32",
"36.65",
"54.5"
]
}
At a website, I found the following code to make a jQuery plugin:
(function($){
// Our code here...
})(jQuery);
I don't understand how the code above works. What I understand is that the code executes immediately because the very last () in function(){}(). So the entire code says that is an anonymous function that is run immediately.
But I don't understand why the wrapping needs to pass jQuery and that inside it needs $ to be passed.
From my understanding, $ is an alias to jQuery, meaning practically the same. What is the meaning of $ and jQuery here? How does the overall code work as a jQuery plugin?
I was asked to implement a menu bar that is neither horizontal nor vertical. Here are two example buttons:
This is something new to me, so to learn how to make this work I'm looking for a site (or better yet, a tutorial) that uses a similar menu bar. Any ideas?
Looking at this jQuery example, how can I modify the code so that it only changes the color of the cell if the value of the submit button in that cell is a certain value.
i.e.-
var submitEl = $("td :submit")
//Only do the below if the submit buttons value is "XYZ"
.parent('td')
.css({background:"yellow", border:"3px red solid"})
I've got a few DOM elements, say text-field input A, B, C, and all of them have the property of 'onclick'. How do I find to which object a particular 'onclick' belongs?
I know that the live() event handles event bubbling different than all other jQuery events. jQuery recommends using 'return false', but in my case that doesn't work.
The issue is:
I have a DIV which contains an anchor tag.
The DIV is bound using live(). Whenever I click the anchor tag inside this DIV it bubbles and calls the DIV's event. If I bind an event to that A tag which returns false it prevents the link from opening. Neither stopPropagation() or return false work in this case. Are there any other options? Ideally I'd like to keep the live() event around.
Hey Guys,
I had made website. This is Link for that.
There is one menu in this site which works well in Firefox , Chrome, Opera.
But it is messed in the IE 6.
I want to know why is not showing correctly?
Hey, say I have a text node via XPath. How would I replace the text node with a new DOM node? For example, this little patch of code will go through text nodes, and if text matches something, it will replace it with a corresponding image via img element.
I wanted something faster then a global page regex or even a element innerHTML regex. Any help would be appreciated.
EDIT: Never mind. I figured it out.
I am wondering what the idiomatic way to render special language characters is using Handlebars.js templates. When I render the normal html I can use something like the Spanish lowercase e, é, and it renders as expected. When I pass the same text as a string to my Handlebars template I just see the characters é.
I have tried creating a Handlebars helper that used jquery to render the text using .html() then returning the .html() of the tmp element and I get the same results.
I'm trying to build a sort of resource allocation form. I'd like to be able to print a table from a database, and then allow users to click on each cell that they would like to reserve. Also, being able to drag and select multiple cells. Then send all of this via $_POST to another php script.
Problem is, I have no idea where to start.
Any suggestions?