Re: [jQuery] Re: simple jquery question
But if this code will get executed more than once (e.g. in response to user actions), make sure you prefix it with code to remove all of the existing options in the dropdown, otherwise it will be additive. On Mon, Jan 4, 2010 at 5:23 AM, Karl Swedberg k...@englishrules.com wrote: this solution could be simplified a bit: $('h3.example').each(function() { $('#deptFilter').append( 'option' + $(this).html() + '/option' ); }); --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Jan 3, 2010, at 6:53 AM, Paul Hutson wrote: This will do what you want, first I assigned the elements via a filter : elements = $('h3').filter('.example'); Then I scrolled around the items found and output them to a span for debugging. elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html()); }); Here's the entire test code : html head script type=text/javascript src=http://ajax.googleapis.com/ajax/ libs/jquery/1.3/jquery.min.js/script script type=text/javascript $(document).ready(function(){ elements = $('h3').filter('.example'); elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html ()); }); }); /script /head body h3 class=example LALALA /h3 h3 class=notexample NOT example :) /h3 h3 class=example Blub /h3 brbr span id=Output /span /body /html On Jan 2, 8:25 pm, jason jasona...@gmail.com wrote: Hey, was wondering if anyone could help me with a basic JQ question. Ok so I am trying to select each element that has a certain class on my page, and then use what is inside of the h3 class=example I am selecting to populate a drop down select box with the id of deptFilter. (with each result found inside of the H3, wrapped in option tags.) I am having trouble understanding how I actually store the variables found in each H3 with the class of example. Any help would be greatly appreciated. -- John Arrowwood John (at) Irie (dash) Inc (dot) com John (at) Arrowwood Photography (dot) com John (at) Hanlons Razor (dot) com -- http://www.irie-inc.com/ http://arrowwood.blogspot.com/
Re: [jQuery] Re: simple jquery question
this solution could be simplified a bit: $('h3.example').each(function() { $('#deptFilter').append( 'option' + $(this).html() + '/option' ); }); --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Jan 3, 2010, at 6:53 AM, Paul Hutson wrote: This will do what you want, first I assigned the elements via a filter : elements = $('h3').filter('.example'); Then I scrolled around the items found and output them to a span for debugging. elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html()); }); Here's the entire test code : html head script type=text/javascript src=http://ajax.googleapis.com/ajax/ libs/jquery/1.3/jquery.min.js/script script type=text/javascript $(document).ready(function(){ elements = $('h3').filter('.example'); elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html ()); }); }); /script /head body h3 class=example LALALA /h3 h3 class=notexample NOT example :) /h3 h3 class=example Blub /h3 brbr span id=Output /span /body /html On Jan 2, 8:25 pm, jason jasona...@gmail.com wrote: Hey, was wondering if anyone could help me with a basic JQ question. Ok so I am trying to select each element that has a certain class on my page, and then use what is inside of the h3 class=example I am selecting to populate a drop down select box with the id of deptFilter. (with each result found inside of the H3, wrapped in option tags.) I am having trouble understanding how I actually store the variables found in each H3 with the class of example. Any help would be greatly appreciated.
[jQuery] Re: simple jquery question
This will do what you want, first I assigned the elements via a filter : elements = $('h3').filter('.example'); Then I scrolled around the items found and output them to a span for debugging. elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html()); }); Here's the entire test code : html head script type=text/javascript src=http://ajax.googleapis.com/ajax/ libs/jquery/1.3/jquery.min.js/script script type=text/javascript $(document).ready(function(){ elements = $('h3').filter('.example'); elements.each(function() { $('#Output').html($('#Output').html() + br + $(this).html ()); }); }); /script /head body h3 class=example LALALA /h3 h3 class=notexample NOT example :) /h3 h3 class=example Blub /h3 brbr span id=Output /span /body /html On Jan 2, 8:25 pm, jason jasona...@gmail.com wrote: Hey, was wondering if anyone could help me with a basic JQ question. Ok so I am trying to select each element that has a certain class on my page, and then use what is inside of the h3 class=example I am selecting to populate a drop down select box with the id of deptFilter. (with each result found inside of the H3, wrapped in option tags.) I am having trouble understanding how I actually store the variables found in each H3 with the class of example. Any help would be greatly appreciated.