0

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.

5
  • Correct me, but if you remove everything from a string except "keep-url", then why not simply change the string to "keep-url", if the original string contains it? Commented Aug 30, 2017 at 9:17
  • I think, question should be how to get specific question from string. It should be resolved using regex Commented Aug 30, 2017 at 9:21
  • but, i have some strings with different url Commented Aug 30, 2017 at 9:28
  • Try this var src = document.getElementsByTagName("iframe")[0].getAttribute('src'); Commented Aug 30, 2017 at 9:28
  • My string just a pure text, it's not <iframe> tag, you can see jsfiddle.net/ducrat/yhq1v31e Commented Aug 30, 2017 at 9:32

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

1 Comment

@Rajesh "Concurrency is hard" :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.