XristosK
XristosK

Reputation: 264

Jquery drop-down menu: how to each() for each item

I need to run a function for each item in a drop down menu. The code is:

    $( document ).ready(function() {
     $('[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"]')
            .each(function(index) {
/* here, I need to do some manipulation on the item */
                  console.log("index is:"+???+"value is"+???);
            });

    });

I understand that i need to put something before each() to select all items but I don't know what to put

Thank you

The drop down menu is :
<select id="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b_$LookupField" title="Εισ. Δικηγόρος/οι">
<option value="0">(None)</option> <option value="1">(Name1)</option>  etc

Upvotes: 0

Views: 9902

Answers (3)

Praveen
Praveen

Reputation: 56519

.each(index, value) //2 parameter with index as well as value

In your case value returns the htmlElement as object so use $(this).val()

so you can have

$('[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"]
         > option').
            .each(function(index, value) {
      console.log("index is:"+index+"value is"+$(this).val());

Upvotes: 1

Kiran
Kiran

Reputation: 20313

Try this:

$(document).ready(function(){
    $('select[id*="lwayer_x002d_EisDikigoros_1eef9a23-7a35-4dcf-8de9-a088b4681b2b"] option').each(function(index,value) {
        console.log("index is:"+index); // index
        console.log("value is"+$(this).val()); // dropdown option value
        console.log("dropdown text value is"+$(this).text()); //dropdown option text
    });
});

DEMO

Upvotes: 1

uma
uma

Reputation: 2952

I think that It will help you.

$("#dropdownid option").each(function(){
  /* write code what ever you want to do */
});

Upvotes: 0

Related Questions