domlao
domlao

Reputation: 16029

JQuery text() is not working in Internet Explorer 7

I developed a simple webapp using asp.net, C# and jquery and I'm testing my app using Internet Explorer 7. I used ajax to retrieve data from the server. But calling the text() of jquery is not working, instead it will call the val() method, for example I created a drop down list called NameDrp, then,

$("SELECT#NameDrp option:selected").text()

The above call will give the value not the text.

EDIT: markup of the select

<select id="NameDrp" name="NameDrp">
   <option value="1">Monkey</option>
   <option value="2">Lion</option>
   <option value="3">Tiger</option>
</select>

Upvotes: 0

Views: 997

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206078

DEMO

$("select#NameDrp").change(function() {
    var text = $("select#NameDrp option:selected").html();
    $('#test').html(text);
});

you can use .text() or even .html()

DEMO2

var arrTxt = [];
$("#NameDrp :selected").each(function(i, selected){
  arrTxt[i] = $(selected).text();
});


  $('#get_val').click(function(){
    alert( 'Value: ' + $('#NameDrp').val() );
  });
  $('#get_text').click(function(){
    alert( 'Text: ' + $('#NameDrp :selected').text() );
  }); 

Upvotes: 2

Related Questions