The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Change default text with Javascrip

2 posters

Go down

Change default text with Javascrip Empty Change default text with Javascrip

Post by !_NICK_! May 4th 2012, 2:33 am

Yes, I know I've asked for a variable change text, but now I need to change the text on just text you can not edit through the templates.

Can I have an example code for this? I previously tried it with this code and there was no success.

Code:
jQuery(function(){var x=document.getElementById('#stats').nextSibling;x.innerHTML=x.innerHTML.replace(/Users browsing this forum:/g,"Users viewing this forum:")});
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 4th 2012, 4:03 am

I figured you or LGforum would post the code and correct me. Javascript is hard for me, I just don't understand why to use all them little symbols.

How could I add multiple things to change?
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by LGforum May 4th 2012, 2:42 pm

RegExp can have spaces in, and you can perform a literal match.

For just changing one word, you don't even need a Regexp, the .replace() will accept just a string as its first parameter.
.replace('browing', 'viewing')
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 4th 2012, 10:33 pm

Could I have the code if I wanted to change more than one text? I can't create all kinds of Javascripts with only one word change. Wink
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by LGforum May 4th 2012, 10:41 pm

If your changing the text in the same element then the .replace function can be chained.

.replace('browing', 'viewing').replace('users','members').replace('forum','section');

But ultimately, it depends what your wanting to change and move around.
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 4th 2012, 11:17 pm

I'm wanting to change a whole new element, I guess you'd call it. Not in the stats.
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 5th 2012, 12:44 am

I know that, but I want to know how I can edit two things without having to create a new javascript.
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 5th 2012, 2:20 am

Can you post me a code of an example?
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 6th 2012, 6:32 pm

Bump!
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 9th 2012, 1:55 am

No, I mean how can I change two things in different element names.
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 10th 2012, 4:22 am

Bump!
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by !_NICK_! May 12th 2012, 12:52 am

Bump again!
!_NICK_!
!_NICK_!
Active Poster

Male Posts : 1505
Reputation : 69
Language : English, HTML, and CSS
Location : In the middle of no return.

Back to top Go down

Change default text with Javascrip Empty Re: Change default text with Javascrip

Post by LGforum May 12th 2012, 3:45 am

Well this is from your first post:
Code:
var x=document.getElementById('stats');
That gets one element ready to manipulate.

Just do the same for another element. Using a different variable name.
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum