Hello Everyone I want to capture label name(72*30) using the following code:
$("input[type = 'radio']:checked:last").each(function() {
var idVal = $(this).attr("id");
var a = $("label[for='"+idVal+"']").text();
alert(a);
});
<script src=".1.1/jquery.min.js"></script>
<li class="radio">
<input class="tmcp-field nav nav-pills dimension-layer-dimension tm-epo-field tmcp-radio" type="radio">
<label id="tmcp_radio_9" >72*30</label>
<span class="price tc-price hidden">
<span class="amount">20 <i class="fa fa-inr"></i></span>
</span>
</li>
Hello Everyone I want to capture label name(72*30) using the following code:
$("input[type = 'radio']:checked:last").each(function() {
var idVal = $(this).attr("id");
var a = $("label[for='"+idVal+"']").text();
alert(a);
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="radio">
<input class="tmcp-field nav nav-pills dimension-layer-dimension tm-epo-field tmcp-radio" type="radio">
<label id="tmcp_radio_9" >72*30</label>
<span class="price tc-price hidden">
<span class="amount">20 <i class="fa fa-inr"></i></span>
</span>
</li>
But the code doesn't alert
anything. What is wrong?
- you can directly get the value using id..? then why – Keerthivasan Commented Sep 30, 2016 at 8:45
- 1 You have given an id to label and can access directly using $("#tmcp_radio_9").text() – Lovepreet Singh Commented Sep 30, 2016 at 8:46
- @KeerthiVasan i have three radio button id is generating dynamically same – techiva.blogspot. Commented Sep 30, 2016 at 8:48
3 Answers
Reset to default 6You can use next()
because your label
is after (next) your input
$("input[type='radio']:checked:last").next().text()
Hope this will help you.
You can see demo here
Use this keyword
$("input[type='radio']:checked").each(function() {
var a= $(this).next().text();
alert(a);
});
Try this also
$("input[type='radio']:checked").each(function() {
var a= $(this).closest("label").text();
alert(a);
});