简体   繁体   中英

Wrap quotes around html in javascript

I have html that looks like this:

var content =  <p>Hello World</p> ;

I want to turn it into something like this:

var new_content =  "<p>Hello World</p>" ;

How would I go about doing this? I am new to Javascript and did some searching but could not find an answer.

var new_content =  '"' + content + '"';

Use this function to wrap in double quotes to the string representation of your HTML.

function wrapWithQuote(text) {
    return '"' + text + '"';
}

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