javascript - How to get the selected radio button label text using jQuery -


i have radio button on page

<div id="someid">     <label class="radio-inline">         <input name="x" type="radio" onchange="getselectedval();">yes</label>     <label class="radio-inline">         <input name="x" type="radio" onchange="getselectedval();">no</label> </div> 

on page load don't want set selection not using checked property. in javascript function, how can value yes or no based on user selection @ runtime?

function getselectedval() {     console.log($('#someid input:radio.........); } 

i have seen similar questions unable find solution of issue.

remove onchange inline handler html. use on bind events.

:checked select checked radio button. closest select parent label , text() label associated radio button. e.g. yes

$('[name="x"]').on('change', function () {      alert($('[name="x"]:checked').closest('label').text());  }); 

demo


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -