简体   繁体   中英

Parse html element in a string using jquery/javascript

I am working in django project in which some data in database are rendered using jquery on page load. The response from jquery is in json format and this json object have values like:

'Hi <b>User</b><br> How are you?' 

I would like jquery to parse this string so that it is displayed correctly.ie

Hi How are you? 好。

I tried $.parseHTML and DOMParser but its not working.

Thanks in advance.

$parsed = $('<div>').html('Hi <b>User</b><br> How are you?' ) works well.

If you want to use only 'Hi <b>User</b><br> How are you?' , you should append $parsed to where you want it put and run $parsed.find('b').unwrap() .

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