Get the details of an article with a html tag later. How to wrap an a tag for the img tag in this paragraph and add a custom attribute to the a tag

clipboard.png









"


Mar.04,2021

after getting the img tag, use the beforeBegin method and then use the setattribute method to add custom attributes


var str='

<img src="/Upload/image/20180419/small/20180419160436_5324_160436_i160436.jpg">

'; var s=str.replace(/(<img [^<]+>)/ig,'<a data-name="aa">$1</a>') console.log(s)
Menu