get value of radio button jquery

Posted by w3diy - 4 months ago

How to get selected radio button value in Jquery?

<!DOCTYPE html>
<html>
<head>
    <title>How to get selected radio button value in Jquery? - w3DIY.com</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>

<input type="radio" name="sex" class="sex" value="male"> Male
<input type="radio" name="sex" class="sex" value="female"> Female
<button>Click to redirect</button>

<script type="text/javascript">

    $("button").click(function(){
        var selValue = $("input[type='radio']:checked").val();
        console.log(selValue);
    });

</script>

</body>
</html>