<head>
<style>
my_found {
background: gray;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
jQuery(function ($) {
$('body').find(':contains("jquery")').contents()
.filter(function () {
return this.nodeType == 3;
})
.each(function () {
var str = this.nodeValue.replace(/(jquery)/g, '<my_found>$1</my_found>');
$(this).replaceWith(str);
});
$('body').contents().each(function () {
if (this.nodeType == 3 && this.nodeValue.indexOf('jquery') != -1) {
var str = this.nodeValue.replace(/(jquery)/g, '<my_found>$1</my_found>');
$(this).replaceWith(str);
}
});
alert($('body').html());
});
</script>
</head>
<body>
<div onclick="alert(1)">jquery text1</div>
jquery
<span onclick="alert(2)">
text2
<span onclick="alert(3)">
text3 jquery
<button>jquery text</button>
</span>
</span>
</body>
<head>
<style>
my_found {
background: gray;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
jQuery(function ($) {
$('body').find(':contains("jquery")').contents()
.filter(function () {
return this.nodeType == 3;
})
.add ($('body').contents()
.filter(function () {
if (this.nodeType == 3 && this.nodeValue.indexOf('jquery') != -1) {
return this;
}
})
).each(function () {
var str = this.nodeValue.replace(/(jquery)/g, '<my_found>$1</my_found>');
$(this).replaceWith(str);
});
alert($('body').html());
});
</script>
</head>
<body>
<div onclick="alert(1)">jquery text1</div>
jquery
<span onclick="alert(2)">
text2
<span onclick="alert(3)">
text3 jquery
<button>jquery text</button>
</span>
</span>
</body>