how can i get that label tag input type="text"
value?
This is not my code and the structure can't be altered
<div id="test">
<label class="control input text">
<span class="wrap">startdate</span>
<input type="text">
<span class="warning"></span>
</label>
</div>
how can i get that label tag input type="text"
value?
This is not my code and the structure can't be altered
<div id="test">
<label class="control input text">
<span class="wrap">startdate</span>
<input type="text">
<span class="warning"></span>
</label>
</div>
Share
Improve this question
edited Dec 18, 2013 at 5:32
Felix Kling
818k181 gold badges1.1k silver badges1.2k bronze badges
asked Dec 18, 2013 at 5:24
jasimjasim
2981 gold badge6 silver badges17 bronze badges
5
- 2 What exactly do you mean by "the label tag value"? Labels don't have values. – Felix Kling Commented Dec 18, 2013 at 5:25
- Now it's even more confusing. "how can i get that label tag input type="text" value?" is not a proper sentence. Do you want to get the value of the input element which is a child of that specific label element? – Felix Kling Commented Dec 18, 2013 at 5:27
- under label tag i have input type="text",i need that value? i am up to this point var item_children=document.getElementById("test"); alert(item_children); var label_item=item_children.innerHTML; – jasim Commented Dec 18, 2013 at 5:29
- You should edit the question instead of clarifying things just in ments. A question should be understandable without reading the ments (or answers). – Jukka K. Korpela Commented Dec 18, 2013 at 5:50
- @jasim do you have used this within any form? You want text box value or label value? where you want to get this value? If you answer these questions means any one can easily solve... – CJ Ramki Commented Dec 18, 2013 at 5:57
3 Answers
Reset to default 6Assuming you don't need to support anything below IE8, you can use document.querySelector
to select that specific input
element and then get its value via its .value
property:
var value = document.querySelector('#test label.control input').value;
Just like that
var value = document.querySelector('#test .control input').value;
you can do that in jQuery
var html = $('#test lable').html();