sorry .up() is prototype... should be .parent() instead.
On Aug 30, 1:20 pm, Josh Powell wrote:
> kali - here is a way to accomplish the same thing in less code, and
> lets you call the images anything you want instead of having to use
> numbers. This is untested so there may be some slight
kali - here is a way to accomplish the same thing in less code, and
lets you call the images anything you want instead of having to use
numbers. This is untested so there may be some slight errors, but the
logic should be sound:
$(function() {
var imageArray = ['foo', 'bar', 'baz'];
Even simpler:
$('img.thumb').click(function () {
$(this).toggleClass('dim');
});
actually got solution in another forum (http://www.manning-sandbox.com/
thread.jspa?threadID=34108&tstart=0)
works like a charm!! :) namely:
$('#image' + i).bind('mouseover', i, function(event) {
$('#image' + event.data).addClass('dim');
});
as to other problem (var elem1 =
Good points by Josh. However this selector example...
$('img[class="thumb"]).mouseover
...can be written simpler as
$("img.thumb").mouseover
It's faster in most browsers to select-by-class than to iterate
elements and 'read attributes'. jQuery may process both syntaxes the
same (?), but us
for (i = 1; i < 5; i++) {
$('#thumb' + i).bind('mouseover',function(event) {
$(this).addClass('dim');
});
}
The 'i' you've called here is a global variable, in a for loop always
put a var in front of it to have local scope (to the function, not
block)
for (var i = 1; i < 5;
Something I forgot to mention in my previous reply... To make sure it's
clear what code is actually being run in the browser, never rely on looking
at your JSP source to understand it. That's what threw you off here. The
browser never sees your JSP source, only the HTML/JS/CSS/whatever files that
You can't call jQuery from JSP code, only from JavaScript.
Your JSP code *generates* JavaScript code, which is what actually calls
jQuery.
In your JSP code, the loop is run in JSP, and it generates a separate block
of JavaScript code each time through the loop. Here is the actual JavaScript
code
yes I know they are two different things, I do know both JSP and
JavaScript, so I do know the difference; I would like to know why what
works in JSP doesn't work in JavaScript.. again:
this works in JSP:
<% for (int i = 1; i < 5; i++) { %>
$('#image<%=i%>').bind('mouseover',function(event) {
I have difficulties understanding what you're trying to achieve.
As someone mentioned, Java is to Javascript as Ham is to Hamster.
They're two different beasts.
For the 'elem+1' situation, you can do:
this['elem'+1] = '...';
to dynamically create variables. But usually you don't have to resor
10 matches
Mail list logo