简体   繁体   中英

Append closing then opening HTML tag with Javascript/Jquery

I have a scenario and in that I want to append a closing tag then some other tag after that opening Tag of the first closed Tag. For Example: I have this code <ins>123678</ins> and I want to append <b>46</b> in between 3 and 6 . I tried this code while putting my cursor in between 3 and 6

document.execCommand('insertHTML',false,'</ins><b>45</b><ins>');

But it is not giving me desired output. I want my output like this

<ins>123</ins><b>45</b><ins>678</ins>

You could try to replace

<ins>123678</ins>

with

newHTML = "<ins>123" + "<b>45</b>" + "678</ins>"

using jquery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM