Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Setting onclick value for a link



12:37 am on Jun 22, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month

I'm trying to remove my inline javascript from my website and set all intrapage links (anchor links) on a page to run the 'doThis' function.

Unfortunately I can't figure out how to set the onclick value. I'm also wondering if this is the best way to detect intrapage links (this script would be running on lots of different websites).

for(i = 0; i < document.links.length; i++){
if(document.links[i].href.indexOf(window.location.host+window.location.pathname+'#') !== -1){
document.links[i].onclick = "return doThis(this.href)";}}


5:27 pm on Jun 22, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Because I'm exhausted and a little lazy right now.

Featured Threads

Hot Threads This Week

Hot Threads This Month