code_junkie

jQuery get select option text

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <select id='list'>
  2. <option value='1'>Option A</option>
  3. <option value='2'>Option B</option>
  4. <option value='3'>Option C</option>
  5. </select>
  6.  
  7. $("#list[value='2']").text();
  8.  
  9. $("#list option[value='2']").text()
  10.  
  11. $("#list option:selected").text();
  12.  
  13. $("#list option:selected").each(function() {
  14. alert($(this).text());
  15. });
  16.  
  17. $("#list option[value=2]").text();
  18.  
  19. $("#list").change(function() {
  20. alert($(this).find("option:selected").text()+' clicked!');
  21. });
  22.  
  23. $(this).find("option:selected").text();
  24.  
  25. $("#list :selected").text();
  26.  
  27. $(this).find("option:selected").text();
  28.  
  29. $("#list [value='2']").text();
  30.  
  31. function selected_state(){
  32. jQuery("#list option").each(function(){
  33. if(jQuery(this).val() == "2"){
  34. jQuery(this).attr("selected","selected");
  35. return false;
  36. }
  37. });
  38. }
Add Comment
Please, Sign In to add comment