How to get the id of element clicked on
Greetings all,
I'm just learning JQuery. I have a page of td cells that are created dynamically using PHP5. The id="" for each td cell is also created dynamically, meaning I do not know what they are or how many.
<td id="<?php print $i; $i++; ?>">
When I click on one of these td cells, how can I use JQuery to get the id of that td cell? I've tried these, but get an "undefined" in my pop-up.
jQuery(document).ready(function(){
$(this).click(function(){
var pos = $(this).attr("id");
alert("id: " + pos);
});
})
and
jQuery(document).ready(function(){
$(".click").click(function(){
var pos = $(this).attr("id");
alert("id: " + pos);
});
})
Also, is there a way to get a serialized value of all the td elements?
Thanks in advance.
YankeeFan