my notmypt
my notmypt

Reputation: 55

extract text between string - javascript

I have a string:

<iframe src="keep-url" width="125" height="290" frameborder="0" scrolling="no"></iframe>

I want to remove all except:

keep-url

and using Javascript, jquery, with jsfiddle
Thank you.

Upvotes: 0

Views: 193

Answers (2)

Richard
Richard

Reputation: 108975

Use jQuery to create the element (without adding to the document) and get the attrribute:

$src = $(theString).attr('src');

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337560

You don't need to extract text from the string, you can get the src attribute from the element:

var src = $('<iframe src="keep-url" width="125" height="290" frameborder="0" scrolling="no"></iframe>').attr('src');

console.log(src);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Upvotes: 1

Related Questions