473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

replace part of link

Hello,

I'm using jquery but I think this could be done with pure javascript. I have links like

[HTML]<div id="statisticstype">
<a href="#statistics/day/type:songs">Songs</a>
<a href="#statistics/day/type:albums">Albums</a>
</div>[/HTML]

now before this I have an option to set range (day,month,year). Now could I replace only "day" with something else?
Feb 29 '08 #1
4 1152
nomad
664 Expert 512MB
Hello,

I'm using jquery but I think this could be done with pure javascript. I have links like

[HTML]<div id="statisticstype">
<a href="#statistics/day/type:songs">Songs</a>
<a href="#statistics/day/type:albums">Albums</a>
</div>[/HTML]

now before this I have an option to set range (day,month,year). Now could I replace only "day" with something else?

day is part of the path. so if you change day to year you will need to have a folder called year.

nomad
Feb 29 '08 #2
day is part of the path. so if you change day to year you will need to have a folder called year.

nomad
it's not important if I'm gonna have folder or not. What I want is to change the value of href, for example

from

Expand|Select|Wrap|Line Numbers
  1. #statistics/day/type:songs 
to

Expand|Select|Wrap|Line Numbers
  1. #statistics/year/type:songs 
there could be also more options after type:songs so this need to stay untouched...
Feb 29 '08 #3
rnd me
427 Expert 256MB
day is part of the path. so if you change day to year you will need to have a folder called year.

nomad
not true.

notice the hash (#).

these HREFs refer to a location on the current page, and thus the same file and folder.


at any rate, here is code to replace all of them:
Expand|Select|Wrap|Line Numbers
  1. var allAs =  document.getElementsByTagName("a");
  2. var mx= allAs.length;
  3. for(var i = 0; i< mx; i++){
  4.    var it = allAs[i];
  5.    it.href = it.href.toString().replace(/day/g, "year" )
  6. }
  7.  
Mar 1 '08 #4
this is possible, but when we replace it once we can't replace it with something else, so is it possible to make a pattern?
Mar 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

52
by: DJ WIce | last post by:
Hi all, I did make a script/css thing to replace the contextmenu on the website with a new one: http://www.djwice.com/contextmenu.html It works nice in MSIE, but on Netscape (and probable...
12
by: Charlie King | last post by:
As I understand it, the use of FIR* to replace heading tags with images in visually enabled CSS browsers is now frowned upon on the basis that some screen readers will *nor* read back text that is...
3
by: bboldi | last post by:
Hi! I have a string containing a HMTL page.I need to insert target="_blank" where targer attribute is not present within <a... TAG, and replace other target attributes - example target="_self"...
2
by: Evan | last post by:
Hey, I posted this yesterday, but no one had any ideas? C'mon now, I know this isn't that hard, i'm just a little new to javascript, and I can't quite figure this out. I searched and searched to...
6
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
7
by: f pemberton | last post by:
I have a string (xdata) and theres a newline after every 17 characters of the string. I was wondering how I can replace multiple substrings multiple times within a string? To put it another way,...
11
by: Fabri | last post by:
I searched and tried to develop (with no luck) a function to do the following: I have a string that may be: "Le'ts go to <a href="my.htm">my car</a>. Tomorrow I'll have to buy a new car. My...
2
by: Sin Jeong-hun | last post by:
I'm trying to replace \n with @(representing the actual new line character). Of course, \\n should not be replaced. What I'm trying to do is simply what the good-old printf does. For example, "\\n...
3
XtinaS
by: XtinaS | last post by:
I'm trying to write a script for Greasemonkey that will, in LiveJournal, replace a placeholdered embedded YouTube thing with a link to the video. In LiveJournal, you can set an option to have a...
5
by: shapper | last post by:
Hello, I have a text as follows: "My email is something@something.xyz and I posted this @ 2 am" I need to replace the @ by (AT) bu only the ones that are in email addresses. All other @...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.