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
  • 36,413
  • 9
  • 66
  • 103
Romi
  • 4,833
  • 28
  • 81
  • 113
  • 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
  • 36,413
  • 9
  • 66
  • 103
Subir Kumar Sao
  • 8,171
  • 3
  • 26
  • 47
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
  • 34,219
  • 14
  • 75
  • 100