Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,081 members, 7,957,033 topics. Date: Tuesday, 24 September 2024 at 05:20 AM |
Nairaland Forum / Science/Technology / Programming / Hashtag Highlighting Like Twitter With Javascript (2255 Views)
Building A Word Scramble Game With Javascript (text Based) / How To Get A User IP Address With Javascript / I Bet You Cant Do This With Javascript, *check Out* (2) (3) (4)
Hashtag Highlighting Like Twitter With Javascript by Cybergenius(m): 11:25pm On Aug 27, 2014 |
Hey folks i need your help. I would like to know how to select the hashtags from a text with JavaScript (ex. #hash) and then apply a html link to the hashtag as follows... "DEMO":. I tried something like this -> "DEMO": this selects the hashtags, but how do i make the hashtag an html link. Thank you |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 10:06pm On Aug 28, 2014 |
It's been a while I checked this section, na heavy school workload ooo! Bros, manage this little code and let's see how it can be made even better with the contribution from others linkify_hashtag=function(t){ t=t.replace(/(^|)#(\w+)/gi,function (s){return '<a rel="nofollow" href="?h='+s.replace(/#/,'%23') +'">'+s+'</a>';}); return t.replace(/\/@/gi,"/"} $(".hashtag".each(function(){$(this).html(linkify_hashtag($(this).html()));}); I'm hereby calling all my ogas at d top ['dhtml18', 'webdezzi', 'asalimpo', 'codehouse', 'seun', ',,,'] and all javascript hackers in the house to come and make this code better ooo, let us learn something new from the well of your knowledge. (probably shorter SLOC and faster speed) |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 10:08pm On Aug 28, 2014 |
chai! so oga Seun neva give us syntax highlighter 4 dis department, diaris god oooo! |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 10:49pm On Aug 28, 2014 |
^^^Hehehe |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 2:28am On Aug 29, 2014 |
olucurious:
of the 3 test scenarios, the second one should not be linkified, reason is we can have innocent URLs like http://webdezzi.com/index.php#tutorial which we don't really want to touch so why not set it that the # starts the line OR whitespace# thats why i have the (^|\s) up there and since you have gone the grouping route, why not ditch the function and just use the named groups directly for readability sake. dont forget, the $1 is there to help return the whitespace back (if it exists) if i know why you have the 3rd replace, i may be able to merge it into one, you are activating the regex engine 3x even though your browser will gladly render it without visible drag, i think it is better to have just one can you confirm if dot ( . ) is among twitter's allowed username characters because dot isn't regarded as a word in regex, atleast from my test Nice work bro, the last line is one of the reasons i love jquery over traditional javascript you just made a site-wide SELECTIVE search and replace look like bean |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 2:45am On Aug 29, 2014 |
Oga mi sir, thank you sir. Waiting for the other ogas to come and disrupt this thread. |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 2:51am On Aug 29, 2014 |
I am not going to say anything, too damn busy upgrading my site and webdezzi is here already. |
Re: Hashtag Highlighting Like Twitter With Javascript by Nobody: 8:36am On Aug 29, 2014 |
dhtml18: I am not going to say anything, too damn busy upgrading my site and webdezzi is here already. it is hard finding sleep these days, maybe the doctor can prescribe some tablets |
Re: Hashtag Highlighting Like Twitter With Javascript by dhtml(m): 3:25pm On Aug 29, 2014 |
You are making too much money that is why. |
(1) (Reply)
I Need A Crash Course In PHP / Making An App: 6 Things You Should Consider Before Getting Started / Code To Calculate Formula
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17 |