1

Following jQuery is not working on given select box.

I want to iterate through all the options of select box.

Where am I going wrong?

Am not getting alert("hi"), I.E. $("#FileType").find('x:option').each(function(){ is not executing.

<x:select id="FileType" width="210px">
        <x:option value="JPG">JPG</x:option>
        <x:option value="PNG">PNG</x:option>
        <x:option value="PDF">PDF</x:option>
        <x:option value="TIF">TIF</x:option>
        <x:option value="BMP">BMP</x:option>
</x:select>

$("#FileType").find('x:option').each(function(){
    alert("hi");                                
    if($(this).val() == AttachmentExtension)
    $("#FileType").val(AttachmentExtension);
});
George
  • 35,662
  • 8
  • 61
  • 98
Romi
  • 4,693
  • 28
  • 77
  • 112
  • See http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces for using xml namespaces with jquery – Tetaxa Mar 25 '13 at 09:24

2 Answers2

2

You need to escape the : character in the selector.

$("#FileType").find('x\\:option').each(function(){
// Your logic. 
});

Here is jsFiddle. http://jsfiddle.net/bVz6F/

George
  • 35,662
  • 8
  • 61
  • 98
Subir Kumar Sao
  • 7,852
  • 3
  • 23
  • 46
1

I am not really sure what technology namespaces your select/option tags but the end result HTML does not have the namespaces. Change to:

$("#FileType").find('option').each(function(){
    alert("hi");                                
    if($(this).val() == AttachmentExtension)
    $("#FileType").val(AttachmentExtension);
});
Konstantin Dinev
  • 32,797
  • 13
  • 71
  • 95