I’m using a ajaxLink to try to delete a certain news of a group of news with AJAX. i want to hide the div container of the deleted news but how can I identify the div with Jquery? I get no access to the assigned ID of the AJaxLink, right?
I have some destinations and some flights between the destinations and I don’t use a YII-Widget to show it.
Here some Pseudocode to explain my problem:
Pseudocode:
foreach($model->destinations as $i => $destination) {
<div class="destination">
echo $destination->name; // Line 1
echo CHtml::ajaxLink($iconDel, array('trip/deletedestination', 'id' => $destination->id, 'tripid'=>$model->id), array(
'type'=> 'GET',
'success'=>'function(data) {
// after success I want to delete the specific DIV with a fadeout with Jquery
}'
), array('confirm'=>'Are you sure you want to delete this item?',
'class'=>'deletebutton' )); ?>
<div>
<br>
<div class="flight">
echo $destination->arrival_journey['days']; //line 2 .. It's the flight between the destinations
<div>
}
When the User press the delete button I delete the destination (and if exist the flight) and after success I want to fade out the deleted DIV (destination and flight) but how can I do this? I cannot fadeout the class. I don’t have a ID of the div.
Then you need to use the ID… currently you set the ID of the div to $destination->id, it woudl be good to set it to somethinglike "AX"+$destination->id… then in the success method use that same formula to get the jQuery object… something like
If you think if it’s a good practice to set a custom ID and then use it, that’s the only way to go.
But [size="2"]regarding best practice…[/size]
[size=“2”]in your example above, as you have a foreach loop and there can be undefined amount of DIVs and links, for example 10 or more, it’s not a good practice to use ajaxLink() at all, because it will generate 10 or more JS codes. Just check the generated page (view source) and you will see there repetitive JS code.[/size]
[size="2"]So the best solution is to use a classic LINK and then add a custom JS code to manage the interactive (ajax) part.[/size]