简体   繁体   中英

HTML tag showing as a string

Please check my code and let me know what I am doing wrong

 $('ul.ne.elBulletList.listSize1.listImage32.listBorder0 li').text(function(_, text) {
        // return (); // just the original requirement
        str = `<div class="heading">`;
        str += text.split('-', 1).pop();
        str += `</div><div class=text">`;
        str += text.split('-').pop();
        str += `</div>`;
        // console.dir(str));
        return innerText = str; // with whitespace removed
      });

Html is displaying as a plain text. can anyone tell me what is wrong I am doing.

Thanks

.text( text )

We need to be aware that this method escapes the string provided as necessary so that it will render correctly in HTML. To do so, it calls the DOM method .createTextNode(), does not interpret the string as HTML.


.html( function )

A function returning the HTML content to set

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