0

I know how to get the value of a selected option but i am wondering how to get its text.

this is how i access the option using the value ?

$('#dropdownId').children('option[value="'+5691+'"]').hide(); 

something like below,

$('#dropdownId').children('option[text="'+'some text'+'"]').hide(); 
1
  • 1
    Looks like you try to get element by contained text insteed of getting text of element. So you've got a lot of irrelevant answers... Commented Jul 3, 2013 at 12:03

5 Answers 5

2

try:

$('#dropdownId').children('option[value="'+5691+'"]').text() 
Sign up to request clarification or add additional context in comments.

1 Comment

He need to get element not text.
1

Use this:

.children("option:contains('"+text+"')") 

3 Comments

how can i lower case the text ? is something like this is possible. lower(text) ?
yes, native js .toLowerCase() method: .children("option:contains('"+text.toLowerCase()+"')")
tnx but i want something like below...... i have this... $('#dd_type_call').children("option:contains('"+'Hello World'+"')").hide(); Instead of this, I want to check like this. $('#dd_type_call').children("option:lower(contains)('"+'hello world’+"')").hide();
1

Use .text().

Here's a fiddle - http://jsfiddle.net/friiks/XXsFy/

1 Comment

$('#dd_type_call').children("option:contains('"+'Hello World'+"')").hide(); Instead of this, I want to check like this. $('#dd_type_call').children("option:lower(contains)('"+'hello world’+"')").hide();
0

Try this:

HTML:

<select id="foo"> <option value="1">foo</option> <option value="2">bar</option> </select> 

Java Script:

$(function () { $("#foo").change(function(){ alert($("#foo option:selected").text()); }); }); 

Comments

0

I guess you are trying to achieve some thing like this

if($('#dropdownId').children().text()=="some text") $('#dropdownId').children().hide(); 

Thanks.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.