Basic Bridge
Basic Bridge

Reputation: 1911

Change #hash tag to link on page load

How to change # tag + Character to link using javascript

This is going #right on the way

with

This is going <a href="http://twitter.com/#!/search/right">right</a> on the way

even this is also acceptable

This is going <a href="http://twitter.com/#!/search/right">#right</a> on the way

The page lots's of # (hash) tag in different classes and id's

Upvotes: 1

Views: 2879

Answers (2)

amosrivera
amosrivera

Reputation: 26554

var string = "This is going #right on the way";
string.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>')

Demo: http://jsfiddle.net/dKm82/

Upvotes: 5

bigblind
bigblind

Reputation: 12887

here is my suggestion

(function(){

$.fn.hashlink = function(){
  this.text(this.text().replace(\#(w+)\),"<a href='twitter.com/#!/search/$1'>$1</a>")
  text = \#w+\g.
}    

})

Upvotes: 1

Related Questions