On Fri, Apr 10, 2009 at 5:46 PM, thought thou...@orcon.net.nz wrote:
Given this code:
DIV id=div_one/DIV
DIV id=div_two/DIV
DIV id=div_three/DIV
DIV id=div_four/DIV
Lets say that the user is invited to click one one of these divs.
How do I get the id of the div that was clicked ?
$('div').click(function(){
alert(this.id);
});
On Apr 10, 8:46 pm, thought thou...@orcon.net.nz wrote:
Hi all.
This might be more of a javascript problem rather than a jquery
problem,
but I'm also wondering if there is a 'jquery way' of solving it.
Given this code:
DIV id=div_one/DIV
script type=text/javascript
$(document).ready(function() {
$(div[id^='div_']).click(function() {
alert(this.id);
});
});
/script
Better not to use JQuery for such trivial things as getting the ID attribute
since it's already apart of the
Thanks for the swift replies.
I've got a lot to learn about javascript, and at this point, adapting
charlies code, I get a strange effect that I didn't anticipate, and
don't understand.
$('.thumbnail').live(click, function(){
$(div[id^='thumbnail']).click(function() {
A live handler is different from a normal handler, and I'm not sure
why you're putting a normal handler inside of a live handler. A live
handler works by looking at the target of whatever is clicked and
comparing it to the selector, in this case, the thumbnail class. I
personally prefer to use
So then this behaviour is working because I'm using a live handler?
In this case I am indeed using a live handler because elements of
the thumbnail class don't exist when the document is initially
created,
but are conditionally added at a later point.
I'm reasonably sure that this is an
I think the approach you want is just:
$(div[id^='thumbnail']).live(function() {
alert( $(this).attr('id') );
});
On Apr 10, 4:00 pm, thought thou...@orcon.net.nz wrote:
So then this behaviour is working because I'm using a live handler?
In this case I am
The problem is that you've got a handler inside of a handler. You want
either of these:
$('.thumbnail').live(click, function(){
alert( $(this).attr('id') );
});
$('.thumbnail').click(function() {
alert( $(this).attr('id') );
});
Whether you use $('.thumbnail') or
Thanks guys.
It looks like Brians first fragment addresses the problem I have.
On Apr 11, 2:04 pm, brian bally.z...@gmail.com wrote:
The problem is that you've got a handler inside of a handler. You want
either of these:
$('.thumbnail').live(click, function(){
alert(
9 matches
Mail list logo