Hi Ron,
you should be able to do this with the .wrapAll() method:
http://docs.jquery.com/Manipulation/wrapAll
Something like this, maybe:
$('input:radio').each(function() {
var $next = $(this).next('label');
var $both = $(this).add($next);
if ($both.length == 2) {
$both.wrapAll('<span></span>');
}
});
There's probably a better way to do it, but I'm pretty sure this will
work.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Feb 12, 2008, at 9:26 PM, Ron Hall wrote:
I have HTML code that looks like this:
<input type="radio" name="my_button" id="my_button" value="Yes" /
<label for="my_button">Yes</label>
And I need to wrap all of it in SPAN tags. Like this:
<span><input type="radio" name="my_button" id="my_button"
value="Yes" /
<label for="my_button">Yes</label></span>
I tried to use code similar to this to do it.
$(document).ready(function(){
$("input").before("<span>");
$("label").after("</span>");
});
But it did not like the opening and closing tags to be separated. The
browser would self close the opening tag and ignore the closing tag.
I then thought to use wrap but I cannot figure out from the
documentation how to select both tags together so it sees them as one
unit to be wrapped. Any ideas?
Thanks,
Ron