Reputation: 4886
can anyone please tell me how to send div id through button click java-script parameter. Here in the below code the main div id 'ricId_1' and the class name "ric_class1 rico_class0 ric1_class1 ric2_class3" is created dynamically has to be send through javascript method cancel('divid') in the button click.The div id is not static.
<div id="ricId_1" class="ric_class1 rico_class0 ric1_class1 ric2_class3" style="width: 730px; left: 309px; top: 71.5px; z-index: 13000; display: block;">
<div class="ricTitle">
:
</div>
<div class="ricModal ng-scope" style="height: auto;">
:
<div>
<div>
<div ng-controller="Manage" class="ng-scope">
<div class="ricG ricAlign">
<div class="ricGrid"><div class="ricGridTable">
:
</div>
</div>
</div>
</div>
<div align="center" class="row btn-group">
<button onclick="cancel('divid')" class="ricButton" type="button" id="sss" ric:loaded="true">Close</button>
</div>
</div>
Upvotes: 1
Views: 3270
Reputation: 148110
Pass the button to cancel and use that id to get the closes ancestor with class ric_class1 rico_class0 ric1_class1 ric2_class3
having id ricId_1
Html
<button onclick="cancel(this)" class="ricButton" type="button" id="sss" ric:loaded="true">Close</button>
Javascript
function cancel(btn)
{
ricId_1 = $(btn).closest('ric_class1 rico_class0.ric1_class1 ric2_class3');
//or
ricId_1 = $(btn).parent().parent();
}
Upvotes: 3
Reputation: 2853
Try this
HTML
<div id="ricId_1" class="ric_class1 rico_class0 ric1_class1 ric2_class3" style="width: 730px; left: 309px; top: 71.5px; z-index: 13000; display: block;">
<div align="center" class="row btn-group">
<button class="ricButton" type="button" id="sss" ric:loaded="true">Close</button>
</div>
</div>
jQuery Code
$('.ricButton').on('click', function(){
var getId = $(this).parent().parent().attr('id');
alert(getId);
});
Upvotes: 1
Reputation: 17929
pass this
to the function call and retrieve the id
later
JSFIDDLE http://jsfiddle.net/PrX52/
HTML
<button onclick="cancel(this)" class="ricButton" type="button" id="sss" ric:loaded="true">Close</button>
JS
function cancel(el){
alert(el.id);
};
Upvotes: 0