Jquery Id Of A Div


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?

Thx for help



Please post your ajaxlink code and jquery code for access.


chandran nepolean

You can set the ID manually in the last parameter of ajaxlink (htmlOptions)

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:


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 class="flight">

   echo $destination->arrival_journey['days']; //line 2 .. It's the flight between the destinations



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.

I hope it’s more clear.

Thx a lot


Not sure if it will work (can’t try right now) but worth to check… try with $(this).parent() to get the DIV

I already tried… it doesn’t work = undefined

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

'... $("#AX'+$destination->id+'")...'

Hey… I’m not sure that this is best practice but it works! :slight_smile: Thx a lot

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]

[size="2"]Something like this:[/size]


<?php foreach($model->destinations as $i => $destination): ?>

	<div class="destination">


	echo $destination->name;

	echo CHtml::link($iconDel,



			'id' => $destination->id,









<?php endforeach;?>


	Yii::app()->clientScript->registerScript('ArtistJS', <<<EOD


	if(confirm("Are you sure you want to delete this item?")) {


			url: this.href,

			context: this,

			type: "GET",

			success: function(data) {





	return false;



	, CClientScript::POS_READY);


[size=“2”]This way you can have many DIVs and links but only one JS snippet to rule them all. :D[/size]

I tried your way with the link but it doesn’t work because he tries to render the page again.

What do I have to change at the Controller?

public function actionDeletedestination($id, $tripid)