html - JQuery get option text based on same li element -
i working on select option not know how can text option base on option value.
for example text "danish" if value da,
the html of option select below
<div id="language" class="dd-container" style="width: 333px;"> <div class="dd-select"> <input class="dd-selected-value" name="language" type="hidden" value="en"> <a class="dd-selected"><label class="dd-selected-text">english</label></a> <span class="dd-pointer"></span> </div> <ul class="dd-options dd-click-off-close"> <li><a class="dd-option dd-option-selected"> <input class="dd-option-value" type="hidden" value="en"> <label class="dd-option-text">english</label></a> </li> <li><a class="dd-option"> <input class="dd-option-value" type="hidden" value="da"> <label class="dd-option-text">danish</label></a> </li> <li><a class="dd-option"> <input class="dd-option-value" type="hidden" value="nl"> <label class="dd-option-text">dutch</label></a> </li> </ul> </div>
in jquery, able value below statment
var langname = $('li a.dd-option input.dd-option-value[value="da"]').val(); alert(langname);
but not able text this
var langname = $('li a.dd-option input.dd-option-value[value="da"]').text(); alert(langname);
does has solution this?
label sibling of input element. need use correct selector target next label element:
$('li a.dd-option input.dd-option-value[value="da"]').next().text();
Comments
Post a Comment