Wednesday, 15 June 2011

jquery - How can i get the class from the all selectbox options? -



jquery - How can i get the class from the all selectbox options? -

i'm trying class current selected alternative , insert textbox, can first class:

jsfiddle: http://jsfiddle.net/2qawh/

html

<select class="josearchselect" id="templates" name="text"> <option class="1">1</option> <option class="2">2</option> </select> <input type="text" class="log_temp_id" />

jqquery

var element= $(this).find('option:selected').attr('class'); $("#templates").live("change", function() { $(".log_temp_id").val(element); });

and heard live not beingness used anymore in new jquery versions, dont know if true, replace event.

thanks.

you need find class within alter handler

$("#templates").live("change", function () { //you need read class attribute within alter handler selected alternative var classname = $(this).find('option:selected').attr('class'); $(".log_temp_id").val(classname); });

demo: fiddle

the .live() method no longer supported, if wish utilize event delegation back upwards alter event handler utilize .on() method jquery >= 1.7

jquery

No comments:

Post a Comment