tags:

views:

90

answers:

3

Hello,

I am not developer so I need help from you guys.

My Problem is simple.

I just want javascript to hide word before "."

Example :

say for google.com

I just want word ".com" tobe print.

Please note that my content is dynamic so google.com will keep changing everytime to google.net or yahoo.com...... so on..

Thanx in advanced.

A: 

Here's a tutorial for you on how to parse URL's in Javascript. http://java-programming.suite101.com/article.cfm/how_to_get_url_parts_in_javascript

Tom Gullen
Link-only answers aren't appropriate for SO. By all means reference sources when answering a question, but answer the question within the text of your answer. This keeps SO independent of links that may disappear.
T.J. Crowder
Ok! Didn't realise this, thanks for the info.
Tom Gullen
+1  A: 

Well, you didn't mention quite a lot, like how do you get your input? What to do if you have no dot, are many dots?
One simple solution is:

var s = 'before.after';
var pos = s.indexOf('.');
if(pos >= 0) // here, if I don't find a dot, keep s as it is.
   s = s.slice(pos);

alert(s); // .after
Kobi
There's also the dark-magic version: `s = s.replace(/^[^.]*/, '');`
Kobi
I dont want alert, just need to get it print on page itself
MANnDAaR
@manndaar - `alert` is an example. You can use `document.write(s)`, but that isn't best practice. It depends where you want it, how you run the script, and if you need it more than once. Please add these details to your question.
Kobi
Thanx-a-lot Kobi. It worked like charm...
MANnDAaR
A: 

If the content you want to modify is in HTML content, the easiest way is to do string replace.

http://www.bradino.com/javascript/string-replace/

Before using replace, you should first locate the content, by its container ID or Name.

http://www.tizag.com/javascriptT/javascript-getelementbyid.php

http://www.eggheadcafe.com/community/aspnet/3/43154/getelementbyname.aspx

Hope this helps.

ZEAXIF