HIde word with JavaScript
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.
开发者_C百科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.
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
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
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.
精彩评论