Reputation: 25
I'm trying to change all dd's with specific text, in this example "color" from dd to dt elements.
<dl>
<dd><a>color</a></dd>
<dd><a>green</a></dd>
<dd><a>blue</a></dd>
</dl>
<dl>
<dd><a>color</a></dd>
<dd><a>red</a></dd>
<dd><a>orange</a></dd>
</dl>
What would be the best way to go about this?
Thanks
Upvotes: 0
Views: 48
Reputation: 318182
$('dd').each(function() {
if ( $.trim($(this).text()) == 'color' )
$(this).replaceWith($('<dt>' + this.innerHTML + '</dt>'));
});
Upvotes: 0
Reputation: 388316
Try using wrap()/unwrap()
$('dl dd').filter(function(){
return $.trim($(this).text()) == 'color'
}).wrapInner('<dt />').contents().unwrap()
Demo: Fiddle
Upvotes: 1