0

I want the text present in anchor tag which is present in javascript variable.

var a= <a href="javascript:downloadPopup('9374227','CASE','1004030422')">9374227</a>
i want "9374227"
How can i get it?

2 Answers 2

1

Assuming a can be made as a string, use jQuery text()

var a = '<a href="javascript:downloadPopup(\'9374227\',\'CASE\',\'1004030422\')">9374227</a>';

var jQueryAnchor = $(a);//convert to jquery object
var text = jQueryAnchor.text();

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

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

Comments

0

Try this out. It will give you the result as expected.

var temp = document.createElement('div');

    temp.innerHTML = '<a href="javascript:downloadPopup(\'9374227\',\'CASE\',\'1004030422\')">9374227</a>';

var number = temp.childNodes[0].innerHTML;

console.log(number);

Comments

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.