Reputation: 55343
I have some text in the following div: .wpbdp-listing-single
The text has nothing wrapping it. How to trap an HTML tag around it? (without wrapping the other elements that do have html tags?
Upvotes: 1
Views: 383
Reputation: 151893
So you want to only wrap text-only elements of that div. Here's jQuery code that does that:
$('.wpbdp-listing-single').contents().filter(function() {
return this.nodeType == 3;
}).wrap('<b></b>');
Unlike .children()
, .contents()
will return text nodes as well, and you can filter for text nodes only by testing for the nodeType
property.
Fiddle: http://jsfiddle.net/dandv/YkgLa/
Upvotes: 2