Skip to content
Advertisement

search and replace text inside html of div in javascript but not text inside tag

I’ve some HTML structure and i want to search particular text inside that HTML structure. see below example

JavaScript

Now if I’m searching for “span” text then, “span” word should be wrapped with div tag. But only “span” word in text and not from class or other tags.

i want output like this (wrap using div or span)

JavaScript

Advertisement

Answer

JavaScript

I have modifed your html by enclosing with a wrapper for getting my selector. But you can use your own selectors.

JavaScript

This code will do what you need. Here is the jsffiddle for this.

If your problem is fixed then please don’t forget to mark this as solved. Thanks.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement