3 ms·
but there is no such selector 'isChild' that can be paired with :contains as far as i know Maybe you can use $.children()? Something like: $('div').childre
by byoung2 16y ago
but there is no such selector 'isChild' that can be paired with :contains as far as i know
Maybe you can use $.children()? Something like:
$('div').children(":contains('apple')").each(function() {
var html = $(this).html().replace(/apple/,"<b>apple</b>");
$(this).html(html);
});
example: http://www.fillerspace.com/apple.html http://www.fillerspace.com/apple.html
- jdavid 16y agothis doesn't seem to work to well on a complex page like http://techcrunch.com/2010/07/29/apple-location/ http://techcrunch.com/2010/07/29/apple-location/ .
- byoung2 16y agoJust a few small changes fixes it: jQuery('div.entry').find(":contains('apple')").each(function() { var html = jQuery(this).html().replace(/apple/gi,"<span class='apple'>Apple</span>"); jQuery(this).html(html); }); I made the str.replace global and case-insensitive (/apple/gi), and changed $.children() to $.find() since on TC the content wasn't the direct descendant of a div. $.find() goes more than one level down. They also seem to be using jQuery.noConflict() so I changed the $ to jQuery. example: http://fillerspace.com/techcrunch.html http://fillerspace.com/techcrunch.html