For your first question, you can use wrap(). http://docs.jquery.com/Manipulation/wrap
For your second question, if you didn't know, and ID must begin with a letter, not a number. With that in mind, you can do something like: var counter = 1; $("span").each(function() { this.id = 'id_'+counter; counter++; }); This will make ID's for each span (from top to document first) like "id_1", "id_2", etc. To retrieve an ID like that, you can do: $("span").click(function() { var id = this.id.split('_')[1]; // 1, 2, 3... alert(id); }); On Aug 14, 9:01 am, Breno Gazzola <breno.gazz...@gmail.com> wrote: > Hello everyone, I just started using jquery and I'm having some > difficulty figuring out how to do two things. > > First, how do I get this: > <b>Hello</b> > To become this? > <span><b>Hello</b></span> > I know how to do $("b").before("span"), but $("/b").after("span") is > not working. > > Second, how do I get this: > <span>Hello</span> > <span>Hello</span> > To become this? > <span id="1">Hello</span> > <span id="2">Hello</span> > I tried using a counter and replaceWith(), but this method returns a > DOM not an jquery element so .attr(counter) wont work.