javascript - jQuery .each works in jsFiddle but not in my page -
javascript - jQuery .each works in jsFiddle but not in my page -
so i'm trying work jquery's $.each
function, , can't seem work. i'm testing output alerts, no matter alter selector in $('selecter').each
, nil seems happen. console devoid of errors well. i've tried div's, spans, etc..and nil seems work. i'm including jquery 1.10 google cdn, , made sure included before seek run code.
the weird thing can code work in jsfiddle. have ideas why wouldn't working in page?
working jsfiddle: http://jsfiddle.net/cuzv9/
here code:
js:
$(document).ready(function() { $("#searchdropdown option").each(function() { alert($(this).val()); }); });
html:
<select id = "searchdropdown"> <option value = "5, 2, 0, 1"> cycle(5, 2, 0, 1) </option> <option value = "6, 3, 0, 3"> utility(6, 3, 0, 3) </option> </select>
you running code before dom ready manipulated.
put .each function in document.ready(function() {}) syntax
$(document).ready(function() { $("#searchdropdown option").each(function() { alert($(this).val()); }); }
thanks comments
javascript jquery html
Comments
Post a Comment