Changing a tag name

54 views
Skip to first unread message

Dave Smith

unread,
Nov 22, 2009, 3:24:33 PM11/22/09
to phpQuery
Hi phpQuery

Is it possible to change the tag name of an element?

I tried $element->tagName = 'h2'; but that doesn't work.

all the best
Dave

Tobiasz Cudnik

unread,
Nov 23, 2009, 3:18:00 AM11/23/09
to phpQuery
Hi Dave,

It's not directly possible, but you can wrap child nodes with tag you
want and remove the old one. Although you will loose things like
attributes, event listeners and binded data. Of course you can copy
them too.

Use wrap() and contents() (children() skips text nodes). Alternatively
there's also contentsUnwrap(), which is not present in jQuery.
Reply all
Reply to author
Forward
0 new messages