No worries on the XML vs. JSON. It's been interesting to watch your progress
in refactoring the code. I hope it's useful for other people too.
A few notes on the latest version...
* Avoid using ALLCAPS or PARTIALcaps in a variable name. Many JavaScript
programmers will think you intend such
Cool, it will be good to see your continued work. We may be among the last
holdouts in this mailing list - but I figure since the thread started here
we can carry on.
BTW you may notice one bit of annoying repeated boilerplate in that last
version. See how the callback functions for all the
( function( $inner ) {
html.push( $inner.attr('label'), ': ', $inner.text(),
'br/' );
});
});
});
});
html.push( '/div' );
$('#container').append( html.join('') );
}
On Tue, Feb 2, 2010 at 10:54 PM, Michael Geary m...@mg.to wrote
Are you required to use XML? Why not use JSON and avoid all the parsing?
If you have to use XML I can make some suggestions to speed up the code a
bit. But let's see if that is a requirement or not first.
-Mike
On Thu, Jan 28, 2010 at 10:32 AM, augur 312...@gmail.com wrote:
I spent a couple
No offense, but that code is really frightening. Not your fault though.
JSON is not only much faster than all this XML/DOM garbage, but it is *much*
easier to understand and use too!
If you're coding JavaScript, you need to know how to use ordinary JavaScript
objects and arrays, yes?
If you
But that would give you the href for the first A element in the document,
not necessarily the one you clicked.
Going back to the OP's code, this.href would be the easiest way to get it:
$(document).ready(function() {
$(a).click(function(event) {
alert( You clicked
If your current code in the body tag is literally:
onload=getStuff(data)
then 'data' must be a global variable. You can reference this global
variable directly in any of your JavaScript code. For example:
$(document).ready( function() {
getStuff( data );
});
If that's not exactly what your
You can't do a cross-domain POST, nor a cross-domain GET either. It doesn't
matter what kind of data it returns, you can't do a POST at all. It's not a
jQuery limitation; the browser won't allow it for any JavaScript code.
Cross-domain JSONP works because it uses a dynamic script element, not a
.remove() does remove the element from the document head or body, but that
doesn't destroy it. It just makes it available for garbage collection - if
there are no other references to the element.
For example:
var $div = $('divtest/div');
$div.appendTo('body');
$div.remove();
Here we've created
Removing a script element just removes the script's *source code* from the
DOM. It doesn't undo any actions that the script has already performed, such
as defining functions or variables or creating other DOM elements. It
doesn't change their availability for garbage collection at all.
In your
The JSON part of your server response looks fine if you take out the two
line breaks - I assume those are just an artifact of posting with Outlook,
and your actual JSON response is all on one line.
But why does it have the HTML content repeated after the last } that closes
the JSON data? You
The remote XML API is not on the same domain as your page, is it? Then you
can't do it. Browser cross-domain restrictions will not permit it.
The only reason you can use getJSON for cross-domain requests is that it
actually downloads executable JavaScript code with a dynamic script
element, i.e.
If I tell you the (possible) answer, will you turn off the music on the home
page? :-)
Karl Swedberg mentioned in another thread today that you may have trouble in
IE6 if you try to set a background color on a TR. It has to be on the TD's
instead. Maybe this is the case for IE7 too.
So I would
Just to clarify that thought, I really like the music a lot! I just don't
like having it start playing automatically when I visit the home page.
-Mike
On Sat, Jan 2, 2010 at 1:56 AM, Michael Geary m...@mg.to wrote:
If I tell you the (possible) answer, will you turn off the music on the
home
jQuery does have its own selector engine that is used in *jQuery selectors*.
However, it does not add any capabilities that are not already there in *CSS
selectors*.
This is a jQuery selector:
$('.foobar').whatever();
This is a CSS selector:
style type=text/css
.foobar { whatever }
/style
I wouldn't use either version.
Instead, I would change your CSS from:
tr.rowodd { background-color: #FFF; }
tr.roweven { background-color: #F2F2F2; }
to:
tr { background-color: #FFF; }
tr.roweven { background-color: #F2F2F2; }
and then use just one line of jQuery code:
$('#foobar
That .live() code wouldn't work because what you've really written is:
var temp = exp_iphone_get_trans();
$('#transactions ul li a').live('click tap', temp);
Now you can probably see what the problem is with that. By adding the ()
after the function name, you are *calling* the
Unicorns are a mythical creature, and so is that use of parentheses.
Could this be the syntax you were looking for?
(function() {
var $ = window.jQuery;
$(#CollapseExpandTd).click(
function() {
$(#TreeviewTd).toggle();
$(#MenuBarTd).toggle();
});
})();
That puts all the
Don't sweat it, dude.
First off, Eric didn't post the comment you're referring to. And if he had,
I'd be inclined to cut him some slack. After all, Eric's English is *much*
better than my Chinese (or whatever Eric's native language is).
Second, we all post something once in a while that offends
Sorry, but that's not right at all. There is no problem with using 'row' as
a function parameter name in IE.
We're veering into Cargo Cult Programming here, but it's not your fault,
MorningZ. The problem is that we can't see the actual code that's going
wrong, so we're all reduced to guessing.
with replies of post code/
link
whatever i suppose
On Dec 22, 11:04 pm, Michael Geary m...@mg.to wrote:
Sorry, but that's not right at all. There is no problem with using 'row'
as
a function parameter name in IE.
We're veering into Cargo Cult Programming here, but it's not your
, because you can only
have one title tag in a document, and once the page is loaded you can't
add another title tag.
Lucky for the OP, someone followed up with a comment to the effect of,
Dude! Ever hear of document.title? :-)
-Mike
On Tue, Dec 22, 2009 at 8:48 PM, Michael Geary m...@mg.to wrote
You are calling the lengthy jQuery chain *first* and then passing its result
to setTimeout. Your code is equivalent to:
var temp =
$(['li.',o.hoverClass].join(''),this)
.add(this)
.not(not)
.removeClass(o.hoverClass)
.find('ul')
I think you guys are making this too complicated. Just loop through the data
properties:
function dataChanged( a, b ) {
for( var key in a )
if( a[key] != b[key] ) return true;
return false;
}
if( dataChanged(o,n) ) {
it output but the
important code is not running like this.
On 17 Dez., 18:21, Michael Geary m...@mg.to wrote:
You are calling the lengthy jQuery chain *first* and then passing its
result
to setTimeout. Your code is equivalent to:
var temp =
$(['li.',o.hoverClass].join
p.s. If there are extra blank lines in my code samples, those aren't
intentional (especially not that one in the middle of the chain). Gmail is
adding those for some reason!
On Thu, Dec 17, 2009 at 1:19 PM, Michael Geary m...@mg.to wrote:
I'm sorry, I should have spotted the major bug
50 events should be like nothing.
I suspect the problem may be that you're calling
$('#calendar').fullCalendar('renderEvent', calevent, true); separately for
each individual event.
I'm not too familiar with the Full Calendar, but can you use the 'events'
option described on this page:
$(document).ready( function() {} ) and $( function() {} ) are the same
thing. The latter is just a shortcut to the former. If one is acting oddly,
chances are that the other will too.
Richard, $( function() {} ) should *never* call your function more than
once. It definitely shouldn't call it
I'm glad you fixed your problem, but I'm certain that the conclusion (IE
has trouble with a chained ajax call) is wrong. In the code you posted in
the other thread, the chained and non-chained versions are quite different.
You didn't just cut the chain into parts: the non-chained version uses a
In fact, within a single script tag, function definitions happen first,
before any code in that script tag is executed. It would be perfectly
valid to write:
script type=text/javascript
// will be run immediately, but *after* callit is defined
callit();
// will be defined
Put your lines of code in separate script tags.
google.load() uses document.write() to write a script tag into the
document. This script tag is not executed until the current script tag
exits. So your jQuery.noConflict() call is being executed before jQuery is
loaded.
If you break up the script
Looks like we have two threads going on the same topic. :-)
To give you a real code example, I'd need to see the code that makes use of
that 'result' variable you're setting. Where is that code and what does it
look like?
The bottom line is simple: whatever the code is that uses the 'result'
Its a lot of repetetive code int there that i havent made into
fuctions yet so you know haha :)
Thanks again :)
George
On 14 Dec, 18:15, Michael Geary m...@mg.to wrote:
Looks like we have two threads going on the same topic. :-)
To give you a real code example, I'd need to see
T.J., I think you're right on the money.
Joseph, no need to wonder whether you've run into an issue with the
.append() method. Instead, verify whether you actually have the right data
on hand or not.
Where you had this code:
$('#somediv').append(html);
Change it to:
alert( html );
and see
Oh, wait a minute. You said the content *does* show up in the div.
I think you need to post a link to a test page, so we can see what is
actually happening. That would make it a lot easier to help troubleshoot.
-Mike
On Mon, Dec 14, 2009 at 2:15 PM, Michael Geary m...@mg.to wrote:
T.J., I
Wendi, just a tip to help you get the assistance you're looking for: Since
your question doesn't seem to relate to the topic of this particular thread,
people may not notice it.
Could you re-post your question as a new post with its own title that
summarizes the question? That will help people
Good point, thanks for noticing that, Brian.
This is a good example of why it's always helpful to post a link to a live
test page instead of just a code snippet. Then we know what the actual code
looks like and can see it run in the browser.
-Mike
On Mon, Dec 14, 2009 at 4:20 PM, brian
can I do this best?
Michael Geary m...@mg.to
Wendi, just a tip to help you get the assistance you're looking for:
Since
your question doesn't seem to relate to the topic of this particular
thread,
people may not notice it.
Actually the scope rules I described always apply to all JavaScript code,
whether it uses jQuery or otherwise.
They also apply to your $.ajax example. Consider your second version. You
have a result variable declared outside your validator code. The success
function is able to access this
No, the two examples shouldn't work the same. They are both working exactly
as expected.
Let me slightly rewrite each version in a more step-by-step fashion and you
will see why. The first version is equivalent to:
$(function() {
function handleClick() {
clickFunction1();
}
I think you've got it! By George you've got it!
(With apologies both to you and to Rex Harrison and Audrey Hepburn!)
What you describe is not the only way to do it, but it's certainly a good
way.
You just have to understand what variables a function has access to. Of
course a function can
It's probably 'parsererror', not 'parseerror', right?
If you search the jQuery source for 'parsererror', you will find the two
places where that error can be thrown. That may shed a little light on it.
Actually what I would do would be to start stripping down the JSON response
until the error
Eric, you really need to put up a test page so we can try actually loading
it. Otherwise it's too hard to tell what might be wrong. I'm not even sure
what the problem is we're supposed to be looking at!
-Mike
On Mon, Dec 7, 2009 at 11:44 PM, Eric Zhong ericiszhongwen...@gmail.comwrote:
i have
No, there are no IE settings that need to be enabled. jQuery works with
every modern browser out of the box.
Loading a .js file directly from the browser address bar is not how it would
ever be used in the context of a website, so no conclusions should be drawn
from that experience. jQuery will
what difference.
2009/12/8 Michael Geary m...@mg.to
Eric, you really need to put up a test page so we can try actually loading
it. Otherwise it's too hard to tell what might be wrong. I'm not even sure
what the problem is we're supposed to be looking at!
-Mike
On Mon, Dec 7, 2009 at 11
It's pretty hard to tell what could possibly be wrong from just that code
snippet. If you can post a link to a test page that demonstrates the
problem, it will be much easier for someone to help.
-Mike
On Tue, Dec 8, 2009 at 10:17 AM, NovoGeek kris.techg...@gmail.com wrote:
Hi all,
I'm using
Yeah, the eval() is undoubtedly wrong, but that wouldn't be the issue here
if it's never getting to the success callback.
Is there any clue about the error in the arguments passed to the error
callback? You have the wrong parameter list in that function. It takes three
arguments as shown here:
Minifying your code and removing unused code are good ways to reduce your
initial memory footprint, but they won't have any effect on memory leaks.
A memory leak is when the browser's memory use continues to increase, either
as as you interact with a page or when you reload the page or navigate
I'd like to add one thing to Scott's very informative reply...
You may wonder, But I wasn't trying to run the script from the Windows
command prompt! I pasted it into the IE address bar and that's when I was
prompted to open or save it.
Like the doctor said, If that hurts, don't do it.
The
We need to see something closer to a real-life example. There's a bit too
much missing in the code you posted.
In particular, what does the page look like when it actually has more than
one row from your DB in it? I can't tell which part of your HTML would be
repeated per row. What is the exact
is it
that you'd like to know specifically?
-Mike
On Mon, Dec 7, 2009 at 11:11 AM, Michael Geary m...@mg.to wrote:
I'd like to add one thing to Scott's very informative reply...
You may wonder, But I wasn't trying to run the script from the Windows
command prompt! I pasted it into the IE address bar
Don't be so sure about that. I thought the same thing you did, but we were
both wrong: you *can* write multline strings in JavaScript.
Backslash-newline works inside a string just like it does outside one in
normal JS code.
You do have to be careful; there can't be any whitespace after the
Your first example doesn't work because getJSON doesn't return the JSON data
as its return value; it *calls a function* and passes the data as an
argument to that function.
Remember that getJSON is asynchronous. The call to getJSON returns before
the data is even downloaded. Any time you have
It really makes little difference at all. jQuery makes an array of all your
ready callbacks, and when the document is ready it loops through that
array and calls each function. So other than that tiny bit of overhead, the
net effect is exactly the same whether you put all the code in one ready
How do you know the 'if' isn't working correctly? It doesn't play? At this
point we don't know if the problem is with the 'if' statement itself or with
the code inside it. Have you put another alert *inside* the if statement to
verify whether it actually gets there or not?
The 'if' statement is
You're trying to use negative padding, but there is no such thing in CSS:
http://www.google.com/search?q=negative+padding;http://www.google.com/search?q=%22negative+padding%22
Can you use negative margin instead, or some other technique?
-Mike
On Thu, Dec 3, 2009 at 4:51 AM, Duncan Krebbers
guys are the best :P
I didn't know this particularity about jQuery... it's logical
though
Thanks you all for the help and your time.
Att.
Paulo Henrique
;)
On Dec 2, 4:09 am, Michael Geary m...@mg.to wrote:
Don't feel bad. You made it easy for me. Since you'd already done some
The jQuery object - the return value from $(whatever) - is an array-like
object with .length and [0] etc. properties. You don't need to call .get()
on it unless you need an actual JavaScript Array object, which is rare.
The *elements* of the jQuery object - or the elements of the Array that
JSON is far better for use in JavaScript.
It's much easier to access JSON data, since by the time you see it, it's
just ordinary JavaScript objects. It's more convenient and faster too.
Regarding security, this is data that you're generating on your own server
for use in your own website? Then
click on it. This is one of the pages where i use plugins and they
don't work...
Just navigate around and check firebug console.
Some pages are with php errors because they are incomplete, i haven't
uploaded the most recent controllers...
On Nov 30, 2:59 pm, Michael Geary m...@mg.to wrote
a link to a test page. Without the test page, we were just
taking wild guesses. Once the test page was posted, all it took was a couple
of us taking a quick look at it, and bingo!
-Mike
On Tue, Dec 1, 2009 at 2:45 PM, Scott Sauyet scott.sau...@gmail.com wrote:
On Dec 1, 5:31 pm, Michael Geary m
That's a nice solution.
Let's make it easier to follow with some indentation:
$('a.filter').click(function() {
$(this)
.closest('ul')
.children()
.removeClass('active')
.end()
.end()
.closest('li')
Could it be that you are also loading prototype.js or some other library
that redefines the $() function?
Does it find plugin methods if you use jQuery(...)... instead of $(...)...?
Do the built-in jQuery methods show up?
What does it display if you enter each of these lines into the Firebug
There was a pretty good example posted here a few days ago that may have all
the code you need:
http://groups.google.com/group/jquery-en/msg/546500f34de23d79
The problem that Darjana was asking about shouldn't apply in your case; just
be sure to use the full absolute URL to your Server 2.
Glad you tracked that down - pretty nasty bug in Firebug!
Just curious, 1.3 is still a pretty old version. Any reason not to use the
latest Firebug 1.4.5?
-Mike
On Fri, Nov 27, 2009 at 2:43 AM, Eric ikeah...@gmail.com wrote:
Hey there,
Thanks for your answers. Sorry I didn't reply earlier,
If you would post a link to a test page, I'm sure someone can tell you
what's wrong.
Without that, we have to start playing 20 Questions. :-)
First questions:
1) What is the response from the server in both cases?
2) Install Fiddler2 [*] and have it log the session. What does it show?
-Mike
The first thing that caught my eye looking at your code is the missing var
on this line:
lg_pic = $(this).siblings('.lg_pic_name').html();
Surely you don't want to be creating a global variable here? It should be:
var lg_pic =
I think the method you're looking for is .not():
http://docs.jquery.com/Traversing/not
Also, there is a shortcut for your mouseenter/mouseleave pattern called
.hover():
http://docs.jquery.com/Events/hover
If you look at the source code for .hover(), you can see that it is
literally a wrapper
It would really help if you could post a link to a test page instead of
posting code excerpts. For example, I don't see any HTML code that has
id=link-about and your other links. Is that missing from your page, or did
you just omit it in the code you posted? Are the LI elements supposed to be
The problem is in your setTimeout() call.
When you pass a string argument to setTimeout(), that string is evaluated
*in the global context*.
Instead, pass a function to setTimeout() and that function will be executed
in the scope you expect.
Since you're just calling a single function anyway,
message.replace( 'setTimeout', 'setInterval' );
:-)
On Tue, Nov 24, 2009 at 10:30 AM, Michael Geary m...@mg.to wrote:
The problem is in your setTimeout() call.
When you pass a string argument to setTimeout(), that string is evaluated
*in the global context*.
Instead, pass a function
That code will certainly do the trick. Because your anonymous function
expression simply calls crossfade(), you're essentially doing the same as
this:
cInterval = window.setInterval( crossfade, 5000 );
Well, there is a subtle difference. Your code below doesn't evaluate the
name crossfade
You have too much of this. :-)
Remember that every function you call may have a different this. Just
because you had a this in an outer function with the value you want, it
doesn't mean that some other function you call will have the same this -
even if it's nested inside that outer function.
Can you post a link to a test page?
Pretty hard to troubleshoot by just looking at the headers.
Of course, someone will come along and troubleshoot it from the headers
alone and prove me wrong! :-)
-Mike
On Tue, Nov 24, 2009 at 6:50 AM, Eric ikeah...@gmail.com wrote:
Hey there,
A
You found that this line is triggering the error:
$(menu_node).css({left:-+total_widths+px});
But you haven't told us what the value of the total_widths variable at this
point in the code. The content of that variable will reveal the problem.
Also, there are a few things you can do to optimize
Your code could end up looking something like this:
function setValidation( selector, validator ) {
$(document).ready( function() {
var $form = $(selector);
$form.submit( function() {
$form.validate( validator );
var valid = $(this).valid();
Ideas where I screwed up?
Thanks again.
Dave
-Original Message-
From: Michael Geary [mailto:m...@mg.to]
Sent: November-24-09 10:02 PM
To: jquery-en@googlegroups.com
Subject: Re: [jQuery] Create a function?
Your code could end up looking something like this:
function setValidation
You don't need the language=javascript in the script tag; that isn't the
problem.
There is an extra comma at the end of the object literal in your
infiniteCarousel({...}) call. See if removing that helps.
Note that $(document).ready(function() { ... }); and $(function() { ... });
mean exactly
You can't split up a tag like that. Whatever you pass into functions like
prepend(), append(), or html() will be treated (if possible) as a complete
tag.
It would help to know *exactly* what result you are looking for. I'm
guessing you want to have it end up like this:
table
tr
I wouldn't know what to suggest about the IE7 problem without seeing the
code in action. Do you have a test page I can look at?
-Mike
On Sun, Nov 22, 2009 at 4:45 PM, Rua ra2a...@gmail.com wrote:
Awesome thanks that works, but not in ie7?
Michael Geary-3 wrote:
If the word anything
You're welcome to make any changes to jQuery that you want. You can use
jQuery under the MIT license, which puts very few (almost no) restrictions
on what you can do with it. Basically the only two restrictions are that you
have to keep the copyright notice in the jQuery source code, and you can't
So you are saying you want the entire last row of the outer table, not the
last row of the inner table, is that right? IOW, what you want to get back
is this row:
trtdtest/tdtdtabletbodytrtdNew
test/td/tr/tbody/table/td/tr
If that's right, you're just missing a '' in your selector. Change it
Can you post a link to a test page?
It's impossible to tell what is wrong from the .js file you attached. It's
not even JavaScript code: it's PHP code.
The browser doesn't ever see your PHP code. All it sees is the *output* of
the PHP code. There could be any number of things wrong, but there's
I don't think even case 1 will work in all browsers. Some browsers won't
bother loading the image if it has display:none. But they will all load it
if it has visibility:hidden.
Here's how I do it:
jQuery.imageDimensions = function( src, callback ) {
jQuery('img /')
.css({
If the word anything is just part of the text inside the div, then it
doesn't have a DOM element (tag) of its own. This means you can't select it
with a jQuery selector or any kind of DOM manipulation, and you can't apply
a CSS style to it.
What you can do is rewrite the HTML content of your DIV
You would normally expect that to work.
What content-type is your server putting in the header for the JSON data?
That could be throwing it off.
Also note that a bare primitive value (true, false, null, or a string or
number) is not valid JSON. The only valid JSON is either an object enclosed
in
false (and true) and numbers are valid JSON values. You *can* put them in
quotes, but that changes their meaning: they become strings instead of
boolean or numeric values.
It's true that you would want to use the properties of the msg object such
as msg.descrizione, but it's also fine to call
Here is how this really works:
1. Changes you make to the DOM always take effect immediately. If you make
any change to the DOM and then immediately follow that with code that looks
for your change, that code will indeed see the change. For example:
$('#mydiv').html( 'hello' );
alert(
No, the scope of the data parameter is not the problem. The data parameter
is already in scope inside your click handler. (Michel, check the code
carefully - don't you agree? The click handler is nested inside the getJSON
callback.)
If it were broken in IE8 as well as IE7, then I would guess that
it is appending the full URL...any ideas how to get around
this? Thanks,
On Nov 17, 10:37 am, Michael Geary m...@mg.to wrote:
No, the scope of the data parameter is not the problem. The data
parameter
is already in scope inside your click handler. (Michel, check the code
carefully - don't you
Now MorningZ, that is possibly the worst comparison of setInterval() and
setTimeout() that I've ever seen!
(Please take that as a little good-natured ribbing among friends, OK?)
Both setInterval() and setTimeout() are cancelable, using clearInterval()
and clearTimeout() respectively.
The
You shouldn't be thinking in terms of storing the JSON data in a variable
for other functions to use.
Instead, you should *call* those other functions from your success callback,
and pass the JSON data as an argument to those functions.
Remember that Ajax calls are asynchronous (the A in Ajax).
Yeah, I though Michel's reply was a little snippy too. But that aside, he's
right on the specific point that a synchronous Ajax call is to be avoided at
all cost.
It's even worse than he said: In a single-threaded browser like Firefox,
*all* browser windows and tabs are locked up until your Ajax
Avoid 'this'. In the setTimeout() callback, 'this' is the window object!
Instead you can do:
$('ul.News li').each(function( i, element ) {
curTimeInterval += timeInterval;
//alert(element.id); works here
setTimeout(function() {
Thanks for posting the Google URL; that's good information. But name-calling
and foul language are not welcome here.
-Mike
On Sun, Nov 1, 2009 at 1:17 PM, Joonha joonha.sebr...@gmail.com wrote:
You nut bags forgot to mention to the noob,
Use the AJAX hosted Google URL directly in your source
You're talking about this page, right?
http://docs.jquery.com/License
I rewrote it to be more clear and to reflect the actual intent of the
license.
See if your patent attorney finds it more palatable now...
Thanks,
-Mike
On Thu, Oct 29, 2009 at 3:35 PM, David Robertson
You mentioned not being able to pass the event object into your click
function, but I don't see the code where you tried to do that, so I don't
know what went wrong.
In any case, the function-returning-a-function is much more complicated than
you need. Risteli's code is on the right track, but it
If your script tag that loads jQuery is immediately followed by another
script tag that calls noConflict, there should be no race conditions.
You're not putting the noConflict call inside a $(document).ready() or the
like, are you? It should be directly executed in a script tag:
script
If that's true, shouldn't my test case fail in Firefox?
http://mg.to/test/jquery/dynamic-nightly/jquery-dynamic-onload.html
The page does use a nightly from several weeks ago and I haven't tested with
a more recent version - but hopefully it hasn't gotten broken since then.
-Mike
On Mon, Oct
The concept you're looking for is called a closure. Search for:
javascript closure
and you will find all sorts of information about closures.
It really has nothing to do with jQuery or the DOM. Closures are part of the
core JavaScript language and work in any environment where JavaScript is
1 - 100 of 873 matches
Mail list logo