I have embarked on a mission to start using jQuery and JavaScript properly. I'm sad to say that historically I have fallen into the class of developer that makes a lot of really terrible mistakes with jQuery (polluting the global namespace, not caching jQuery selectors, and much more fun stuff - some of which I'm sure I have yet to disco...
A lot of people say that this is asked too much in the comments, which made me hesitant to ask this, but I still have not found a solution in their answers, mostly because (1) they are typically using jQuery and (2) the questions usually contain technicalities I do not understand.
I have a function with a variable inside. The variable i...
I have a variable whose value is the same as an ID on the page. When I do this:
var foo = 'value';
$('#' + foo).thing();
it doesn't work. But this does work:
var foo = 'value';
var bar = '#' + foo; //'#value';
$(bar).thing();
How can I build that selector in a single line? Creating extra single-use variables seems wasteful.
...
I'm trying to make a converter, but i don't know the formula to do this, for example, how do I get the ratio of 85694 of 30711152. So, i can get the % like 85694/30711152*100=0.28 (rounded) but how do I then get the ratio of like 1 in a 100? I believe that'd be around 1:400? But i don't know how to get it exactly or what formula to use.....
I want to use return false to break a .each() but also return a value at the same time. How can I do this?
Please refer to a work-around function to see what I am trying to do:
function HasStores(state) {
var statehasstores = false;
$(stores).each(function (index, store){
if(state == store.state && store.category == "...
Hello SO:
I am using jQuery and a plugin called Galleriffic to display some images and text on a website I am developing. I have only tweaked the CSS (size and color mostly) to fit my page, but for some reason the text that displays for the next image you click appears below the current text then when the old text fades, it slides up to...
below code is working fine in fire fox and google chromo but in Internet explore 9 is not working. its getting error in "map.setUIToDefault();"
var map = null;
var geocoder = null;
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas_big'));
map.setUIToDefault();
map.disableSc...
I am trying to write JavaScript code which, on a mouse click event, sends some parameter (id) to the server-side JSP code. The JSP code then returns a string to the JavaScript.
HTML code for the button:
<button type="button" onClick="function();">Click Me!</button>"
...and the script:
<SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASC...
We have a lot of objects for which we like to implement a simple toString to output attributes of the object. Some of these attributes may be complex objects themselves.
Is there any standard, or simply just a best practice for a style? I'm thinking something like:
[SimpleClassName] { prop1:value, prop2:value }
In which case a nest...
how do i determine the mouse location on an image using javascript when mouse is clicked
...
I'm aware of the hacks using hash tags, however, I need bi-directional communication with larger payloads and higher throughput. Are there any Flash/ActiveX/etc options that make this possible?
...
How can I get jQuery to only do an ajax query one time?
Right now it contacts the server every time a user toggles "Comments (X)"
// Replies - Toggle display of comments
$('.info .reply').click( function() {
$('.reply', this.parentNode.parentNode).toggle();
return false;
});
// Load comments
$('.info .reply', this).mousedown( ...
Reading another SO question about jQuery performance, I started thinking about the point when it becomes worth using event delegation rather than binding to elements individually. I was thinking mainly about jQuery, but I suppose it is probably applicable for Javascript in general.
Event delegation has two main purposes:
allowing han...
I'm trying to get buttons to appear when hovering over an image. The following works:
jQuery('.show-image').mouseenter(function() {
jQuery('.the-buttons').animate({
opacity: 1
}, 1500);
}).mouseout(function() {
jQuery('.the-buttons').animate({
opacity: 0
}, 1500);
});
However, when moving from the image to the button (wh...
Is it possible to change a function that is called by an existing onmouseover or onmouseout event? For the following example is there a way for me to have ChangeItemAEvent change the "ItemA" onmouseover function from ChangeColor() to ChangeColorBack()? Currently I need to declare an entirely new function() that I feel is not elegant bec...
Possible Duplicate:
What is a good jQuery/Ajax lightbox plugin?
I'm not an JavaScript guy, but I believe that jQuery has got that cool Apple-style light box effect. Or am I wrong? How would I implement that? Are there tutorials on how to do this?
Or's there something far cooler than lightbox? (well, I've heard of it like 5 ye...
Could someone explain why this.rel is giving back undefined and also what the regex is supposed to do.
If this.rel is undefined the regex will not work either and is causing some kind of error because the alert underneath will not fire?
$.fn.facebox= function(settings) {
init(settings)
function clickHandler() {
$.face...
Hello, I've been searching lots and found many tutorials for Javascript / jquery on click expandable divs..
e.g. http://www.dustindiaz.com/basement/block-toggle.html
However what I am looking for,is slightly different .. I need to load the div content on click... rather than hidden loading the div in the background... with display:none...
I have two divs, whose heights I would like to control relative to each other. The point of these divs is that when a user mouses over one of them, it expands vertically and the other retracts vertically (smoothed with CSS transitions). Basic markup:
<div class="product">
<h2>Product Name</h2>
<div class="preview" style="backgr...
Can anyone please tell me why doesn't this work on Google Chrome:
val = document.form.option[document.form.selectedIndex].value;
How should I get around this so that other browsers (like IE and FF) don't get screwed up.
Many thanks in advance.
...