Using javascript/jQuery to get attribute values from an HTML string

前端 未结 4 1007
旧时难觅i
旧时难觅i 2021-01-02 09:51

I have an HTML string that contains text and images, e.g.

...

...

I need to

4条回答
  •  误落风尘
    2021-01-02 10:37

    I solved this same issue trying to pull out the src url from an iframe. Here is a plain JavaScript function that will work for any string:

    function getSourceUrl(iframe) {
      var startFromSrc = iframe.slice(iframe.search('src'));
      return startFromSrc.slice(5, startFromSrc.search(' ') - 1);
    }
    

提交回复
热议问题