Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to strip "onCLick" even from a href tag?

Status
Not open for further replies.

lizok

Programmer
Jan 11, 2001
82
US
hello,
i'd like to know what the regex to strip onclick even from a href tag?

ex. i have this code:

<a href=" onClick="return trackclick(' 'Michael Medved USA Today''Campaign \'08 Hasn\'t Followed the Script');">Campaign '08 Hasn't Followed the Script</a>

i need this code:

<a href=" >Campaign '08 Hasn't Followed the Script</a>

as you can see onclick even has redundant code that i don't need and i need to strip it leaving only href url.

Thank you in advance
 
Code:
document.getElementById("linkID").onclick = function () {return true};

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
thanks kaht , but this was not what i was looking for.

i was looking for regex and figured it incase anyone needs it: 'onClick="[^"]*"' where a string that starts with onCLick and ends with " is extracted.

 
thanks kaht , but this was not what i was looking for.

Then you're in the wrong forum. The code I posted above will change the onclick event once the page has been sent from the server to the client.

If you want the onclick event handler to never even be sent from the server to the client in the first place, then you need to make the change in the server side language you are using.

This forum is for client side javascript, which is the solution that I provided.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top