Thứ Tư, 21 tháng 6, 2017

Find src img tag from string with Javascript

var resources = `<p>This component is at least 50% inline styles by volume. I almost left them out, but I decided not to because having them really gives it the desired effect &ndash; the modal sits on top of a gray background that obscures everything behind it, and all you can do is click that Close button. If you try out this code you&rsquo;ll see what I mean.</p>

Find src img tag from string with Javascript
Find src img tag from string with Javascript
<img alt="Modal in action" src="https://daveceddia.com/images/modal-img.png" style="width:400px" />

<h3>How It Works</h3>

<p>The most important parts here are the first few lines, and the&nbsp;<code>onClick</code>&nbsp;handler.</p>

<p>This bit here is responsible for &ldquo;showing&rdquo; or &ldquo;hiding&rdquo; the modal:</p>`

var img,
        urls = [],
        str = resources,
        rex =  /<img.*?src="([^">]*\/([^">]*?))".*?>/g;

        while ( img = rex.exec( str ) ) {
            urls.push( img[1] );
        }

Good look!!!
Previous Post
Next Post

post written by: