0

What Im trying to do

I am trying to copy some text in a div to a Textarea. During this copying, I need to find an replace a number with another number.

This is my HTML

<DateTo>31MAR17</DateTo>

I want to find 17</DateTo> and replace with 20</DateTo> and then paste it into the Textarea.

This is my Fiddle. This works fine without the </DateTo> bit, but when I add it, it doesn't work. Can you guys please help me on this?

FIDDLE : https://jsfiddle.net/c2fny59x/12/

Note : The html tag must be in the find, replace sequence.

1 Answer 1

2

replace

var leftContent = $(".leftPart").text().replace("17", "20");

with

var leftContent = $(".leftPart").html().replace("17</dateto>", "20</dateto>");

note that to get the actual html tags you need to use html() not text(), and that jQuery will force all html tags to lower case in the process.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. But this doesnt work. It shows all the HTML tags in the textarea.
you can set a hidden element's .html(leftContent) and then take its .text() to re-strip the html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.