Reputation: 494
I managed to automatically give a different id to my divs
I have the following
<diw class="ajaxlink">
<div id="post1">
</div>
..link 1 ...
</div>
<div class="ajaxlink>
<div id="post2">
</div>
...link 2 ...
</div>
I want to update a specific div
by selecting the div in the following way
when I click to the link 1, I launched a jquery which
display the correct id ,
if I click the link 1, my command
alert($(".ajaxlink > :first-child").attr("id"));
display post1
if I click the link 2, my command display post2
Fine.
but when I use the update option
'update'=>'.ajaxlink > :first-child'
it updates the post1 and post2 div, where it should update the selected post, the alert displays the correct name of the id (post1 or post2)
Here is the code
<div class="ajaxlink">
<?php echo "<div id='post".$data->id."'>...</div>"; ?>
<?php
echo CHtml::ajaxLink(
'Test request',
array($url_replace),
array(
'update'=>'.ajaxlink > :first-child' ,
'beforeSend' => 'function() {
alert($(".ajaxlink > :first-child").attr("id")); //alert post 1 if I'm in post 1..
}',
)
);
?>
</div>
Can you help me please ?
Upvotes: 0
Views: 74
Reputation: 4157
Since you know the postid, I'd say just use that to form the update ajaxLink:
<div class="ajaxlink">
<?php echo "<div id='post".$data->id."'>...</div>"; ?>
<?php
echo CHtml::ajaxLink(
'Test request',
array($url_replace),
array(
'update'=>'#post'.$data->id,
'beforeSend' => 'function() {
alert($("#post'.$data->id.'").attr("id"));
}',
)
);
?>
</div>
Upvotes: 1