Student Nitk Student Nitk - 5 months ago 14
Javascript Question

Get the division class object on button click using html and javascript to change the header of the division class

<div class="row">
<div class="col-sm-4" id="job0">
<b>
<h3 id="Name0" >fg</h3>
</b>
<button type="button" id="options0" style="display:none;" onclick="someFunction(this.class)" ></button>
</div>
<div class="col-sm-4" id="job1">
<b>
<h3 id="Name1">dfdf</h3>
</b>
<button type="button" id="options1" style="display:none;"></button>
</div>
<div class="col-sm-4" id="job2">
<b>
<h3 id="Name2">dfdf</h3>
</b>
<progress id="lineCoverage2" max="100" style="display:none;"></progress>
<button type="button" id="options2" style="display:none;" ></button>
</div>
</div>


There are three grids, when i click on any button on any of these three grids the header value of that particular grid must be displayed on alert box for this I need the
div
class object, can anyone help to solve this problem?

Answer

Include jQuery in your page and use the following code block

$(document).ready(function() {
     $('button').on('click', function() {
         alert($(this).closest('div').find('h3').text());
     });
 });

BTW I am not sure why the buttons are hidden on your HTML