Manipulating ------------ You can also add content to the end of tags:: >>> d = pq('
you know Python rocks
') >>> d('p').append(' check out reddit') [] >>> print d
you know Python rocks check out reddit
Or to the beginning:: >>> p = d('p') >>> p.prepend('check out reddit') [] >>> p.html() u'check out reddityou know ...' Prepend or append an element into an other:: >>> d = pq('
] >>> d('#test').html() u'
>> p.insertAfter(d('#test')) [
] >>> d('#test').html() u'python !' Or before:: >>> p.insertBefore(d('#test')) [
] >>> d('body').html() u'
...' Doing something for each elements:: >>> p.each(lambda e: e.addClass('hello2')) [
] Remove an element:: >>> d = pq('
Yeah!
python rocks !
') >>> d.remove('p#id') [] >>> d('p#id') [] Remove what's inside the selection:: >>> d('p').empty() [] And you can get back the modified html:: >>> print d
You can generate html stuff:: >>> from pyquery import PyQuery as pq >>> print pq('