Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to extract URL from Anchor tag.

Below Anchor tag is defined in Asp.Net Search.Aspx page.

HTML
<a onclick = "call_new_url({"abxz":1,"emps":"","ufd":1},"http://localhost:8989/Search.aspx?aa=1;")" style="position: relative;"></a>


Now I want to retrieve ONLY http://localhost:8989/Search.aspx?aa=1; PART from anchor tag using JavaScript or jQuery.

Note - There is no href defined in anchor tag.


Can anyone help me on this?

What I have tried:

I tried with indexOf and substring but it's not working.

Is there any in-built method?
Posted
Updated 28-Jun-21 2:13am
v2
Comments
Richard Deeming 29-Jun-21 6:03am    
As you can possibly see from the messed-up syntax highlighting, that tag is not well-formed. You can't nest quotes like that - you would either need to use different quotes for the attribute value and the string values within it, or encode the quotes within the attribute value as &quot;.

onclick="call_new_url('...')"

onclick='call_new_url("...")'

onclick="call_new_url(&quot;...&quot;)"

1 solution

You can use the document tag selector and regex to match any <a/> elements with the onclick event. I've put together an example here on JSFiddle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900