Q:

How to get the selected value and currently selected text of a dropdown box using jQuery?

0

How to get the selected value and currently selected text of a dropdown box using jQuery?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>How to get the selected value and currently selected text of a dropdown box using jQuery?</title>
</head>
<body>
<select id="ddid">
<option id="op1" value="red">Red</option>
<option id="op2" value="green">Green</option>
<option id="op3" value="blue">Blue</option>
<option id="op4" value="white">White</option>
</select>
 <input id="button1" type="button" value="Click!" />
 </body>
 </html>

JavaScript Code:

$(document).ready(function(){ 
  $('#button1').click(function(){ 
   console.log($('#op2').val());
   console.log($('#op4').val());
  console.log($('#ddid :selected').text());
   });
});

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now