That looks like a mix of PHP & javascript. Try this:
<?php
for($x = 0; $x < $items.length; $x++)
{
?>
<tr><td><a href="#" class="Whatever" rel="<?= $items[$x].id ?>" > Get
data </a></td></tr>
<?php
}
?>
JS:
$(function()
{
$('a.Whatever').click(function()
{
alert($(this).attr('rel'));
})
});
On Mon, Jul 13, 2009 at 4:54 AM, mnaveed<[email protected]> wrote:
>
> sorry I did not clear my point, here is what i want to do,
> I am running a PHP for loop, which generates a table. In the table, I
> have a column in which links are generated with an onclick event and
> the item id is set as parameter, so it looks like this,
>
> for(x = 0; x<items.length; x++) // this is a php loop.
> $str =. '<tr><td><a href="#" onclick="getData(items[x].id);" > Get
> data </a></td></tr>
> echo($str);
>
> this is fine, but no i want to attach an overlay with these links,
> there is only one overlay on my page which will be displayed when any
> of the above link is clicked. Data will be loaded from the server. Now
> how can i pass the current items id from the above link to the jquery
> methods for overlay?
>
> I hope I am able to clear my point..
>
> Thanks.
>
>
> On Jul 12, 10:19 pm, brian <[email protected]> wrote:
>> On Sun, Jul 12, 2009 at 12:46 PM, mnaveed<[email protected]> wrote:
>>
>> > Hi,
>> > I am new to JQuery, can anyone help how to generatedynamiclinks. I
>> > have a loop which generate somelinksand for each, an onclick event
>> > is attached, calling a javascript method with some arguments. some
>> > thing like this,
>>
>> > for(x = 0; x<items.length; x++)
>> > <a href="#" onclick="getData(items[x].id);" >Get data </a>
>>
>> > how can i generate such a grid using Jquery. Actually i have to
>> > display an overlay on each click, and data will be loaded dynamically
>> > in the overlay, so how can i pass the ID to the method?
>>
>> Do you want to create thelinks? Where do you want them appended? One
>> after the other? Or should they be appended to individual elements? If
>> the latter, and let's say you have a structure like so:
>>
>> <div class="Items" id="item_0">foo </div>
>> <div class="Items" id="item_1">foo </div>
>> <div class="Items" id="item_2">foo </div>
>> <div class="Items" id="item_3">foo </div>
>> <div class="Items" id="item_4">foo </div>
>>
>> ... you needn't create the loop yourself. You could do something like:
>>
>> $(function()
>> {
>> $('.Items').each(function()
>> {
>> $('<a href="#" title="click me for data">get data</a>')
>> .click(function()
>> {
>> alert($(this).parent().attr('id'));
>> })
>> .appendTo($(this));
>> });
>>
>> });
>>
>> Note that "this" inside the click handler refers to the link, while
>> the appendTo($(this)) refers to the div.