How to use JavaScript or jQuery to wrap a range (from selection) in a web page into a specific tag? -


So I have to find a way to wrap some range in a specific tag using javascript or jQuery.

For example:

  & lt; P & gt; Hey how are you? & Lt; / P & gt; & Lt; P & gt; I am good! & Lt; / P & gt;   

Then use the JavaScript code in the console:

  & lt; P & gt; This is & lt; Mytag & gt; How are you? & Lt; / P & gt; & Lt; P & gt; I & lt; / Mytag> good! & Lt; / P & gt;   

I know how to get a limit from a selection, but I have to find a way to wrap this category.

Thank you!

You can tag the desired area in this way:

HTML & lt; P & gt; Hey how are you? & Lt; / P & gt; & Lt; P & gt; I am good! & Lt; / P & gt; & Lt; P & gt; This is & lt; Span class = "mytag" & gt; How are you? & Lt; / Span & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Span class = "mytag" & gt; I & lt; / Span & gt; & Lt; / Mytag> good! & Lt; / P & gt;

Javascript

  (function () {var test = ''; $ ('. Mytag'). Function (index) {test + = $ (.) .text ();}); // Use the test to be used}};    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -