Search the Community
Showing results for tags '.each()'.
-
Please consider the two following sets of code and explain why the Javascript not work and suggest an alternative where possible. There are zero complaints from the Javascript console. None. And, the var podType is properly identified. I have checked with console.(log) The procedure does not even turnover for the final element. I am baffled. <script> $(document).ready(function() { $('li.podDex').each(function(){ var podType = $(this).attr('id'); $('#podType').mouseover(function() { $(this).css({"cursor": "pointer", "font-weight":"800"}); }) .mouseout(function() { $(this).css("font-weight", "normal"); }); $('#podType').mouseover(function() { $(this).css({"cursor": "pointer", "font-weight":"800"}); }) .click(function() { var chrono_var = $("#chronology_div").html(); $("#main").html(chrono_var); }) .mouseup(function() { $(this).css({"color": "#fadb9d","font-weight": "normal"}); $('body, html').animate({scrollTop: $('#main').offset().top},800); }); }); }); </script> <ul> <li id='linear' class='podDex'>Linear Analysis</li> <li id='clausal' class='podDex'>Clausal Analysis</li> <li id='inversion' class='podDex'>Socratic Inversion</li> <li id='chronology' class='podDex'>Chronology</li> </ul> Mind you, in isolation, when podType refers directly to the appropriate id attribute, what is included in the .each() function works fine! Roddy
-
I have "Checkbox" input with multiple values. <input type="checkbox" name="drug" value="1" /><input type="checkbox" name="drug" value="2" /><input type="checkbox" name="drug" value="3" /> I want to run through this array and alert() all the values. I'm guessing I should use Jquery's .each() command but I'm not sure how to use it. the problem is, I don't understand how to use it so I can get the key and it's value. $.each($("input[name='drug']"),function(i,v){ alert(i+": "+v);}); What am I missing in the main idea?